Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Paulo Miranda
- */
- #include <iostream>
- #include <algorithm>
- #include <string.h>
- using namespace std;
- int vetor[40];
- int memo[40][40][1010];
- int existe(int i, int f, int valor){
- if(valor < 0)
- return 0;
- if(valor == 0)
- return 1;
- if(i == f)
- return 0;
- if(memo[i][f][valor] != -1)
- return memo[i][f][valor];
- int sem = existe(i+1, f, valor);
- int com = existe(i+1, f, valor - vetor[i]);
- if(sem == 1 || com == 1)
- return memo[i][f][valor] = 1;
- return memo[i][f][valor] = 0;
- }
- int main(){
- int n, caso = 1;
- while(cin >> n){
- bool result = true;
- memset(memo, -1, sizeof(memo));
- for(int i=0; i<n; i++){
- cin >> vetor[i];
- }
- if(vetor[0] < 1)
- result = false;
- for(int i=1; result && i<n; i++)
- if(vetor[i] - vetor[i-1] <=0 )
- result = false;
- for(int i=1; result && i<n; i++)
- if(existe(0, i, vetor[i]))
- result = false;
- cout << "Case #"<< caso<<":";
- for(int i=0; i < n; i++)
- cout << " " << vetor[i];
- cout << endl;
- if(result)
- cout << "This is an A-sequence." << endl;
- else
- cout << "This is not an A-sequence." << endl;
- caso++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement