Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <bits/stdc++.h>
- //%lld
- typedef long long ll;
- #define si(a) scanf("%d", &a)
- using namespace std;
- int vetor[25];
- int matriz[25][2005];
- int main(){
- //freopen("in.txt", "r", stdin);
- //freopen("out.txt", "w", stdout);
- int n, t;
- while(si(n)==1){
- si(t);
- for(int i = 0;i<t;i++)si(vetor[i]);
- }
- matriz[0][vetor[0]] = 1;
- for(int i =1;i<t;i++){
- for(int j = 0;j<=n;i++){
- if(j<vetor[i]){
- matriz[i][j] = matriz[i-1][j];
- }else if(matriz[i]==j){
- matriz[i][j] = 1;
- }else{
- matriz[i][j] = max(matriz[i-1][j], matriz[i-1][j-vetor[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment