AlbertMourato

Untitled

Feb 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <bits/stdc++.h>
  3. //%lld
  4. typedef long long ll;
  5. #define si(a) scanf("%d", &a)
  6. using namespace std;
  7.  
  8. int vetor[25];
  9. int matriz[25][2005];
  10.  
  11. int main(){
  12.     //freopen("in.txt", "r", stdin);
  13.     //freopen("out.txt", "w", stdout);
  14.     int n, t;
  15.     while(si(n)==1){
  16.         si(t);
  17.         for(int i = 0;i<t;i++)si(vetor[i]);
  18.     }
  19.     matriz[0][vetor[0]] = 1;
  20.     for(int i =1;i<t;i++){
  21.         for(int j = 0;j<=n;i++){
  22.             if(j<vetor[i]){
  23.                 matriz[i][j] = matriz[i-1][j];
  24.             }else if(matriz[i]==j){
  25.                 matriz[i][j] = 1;
  26.             }else{
  27.                 matriz[i][j] = max(matriz[i-1][j], matriz[i-1][j-vetor[i]);
  28.             }
  29.         }
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment