Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- int main(){
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, cs=0;
- while(cin >> n){
- int a[n], sum = 0;
- cout << "Case #" << ++cs << ":";
- for(int i=0; i<n; i++){
- cin >> a[i];
- cout << ' ' << a[i];
- sum += a[i];
- }
- cout << '\n';
- bool f = true;
- if(a[0] < 1) f = false;
- for(int i=1; i<n; i++){
- if(a[i] <= a[i-1]) f = false;
- }
- if(!f){
- cout << "This is not an A-sequence.\n";
- continue;
- }
- bool ache[sum + 2];
- memset(ache, 0, sizeof(ache));
- ache[0] = 1;
- for(int i=0; i<n && f; i++){
- if(ache[a[i]]) f = false;
- for(int j=sum; j>=a[i] && f; j--){
- if(ache[j - a[i]]) ache[j] = 1;
- }
- }
- if(f) cout << "This is an A-sequence.\n";
- else cout << "This is not an A-sequence.\n";
- }
- #ifdef ERFANUL007
- fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement