Thứ Tư, 27 tháng 4, 2022

QBSEQ C++

#include <bits/stdc++.h>
#define task "qbseq"
using namespace std;
int n,k,a[1001],f[1001][1001];
void nhap()
{
    cin >> n >> k;
    for(int i = 1;i <= n;++i){
        cin >> a[i];
        a[i] %= k;
    }
}
void xuly()
{
    for(int i = 1;i < k;++i) f[0][i]=-1005;
    for(int i = 1;i <= n;++i){
        for(int j = 0;j < k;++j){
            f[i][j]=max(f[i-1][j],f[i-1][(j-a[i]+k)%k]+1);
        }
    }
    cout << f[n][0];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
    nhap();
    xuly();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.