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][200005];
- int main(){
- //freopen("in.txt", "r", stdin);
- //freopen("out.txt", "w", stdout);
- int n, t;
- while(si(n)==1){
- memset(matriz, 0, sizeof(matriz));
- 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;j++){
- if(j<vetor[i]){
- matriz[i][j] = matriz[i-1][j];
- }else if(vetor[i]==j){
- matriz[i][j] = 1;
- }else{
- matriz[i][j] = max(matriz[i-1][j], matriz[i-1][j-vetor[i]]);
- }
- }
- }
- bool l = false;
- for(int i = 0;i<25;i++){
- if(matriz[i][n]==1){
- printf("Forma\n");
- l = true;
- break;
- }
- }
- if(!l){
- printf("NaoForma\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment