zoukankan      html  css  js  c++  java
  • (1.1.9)UVA 10930 A-Sequence(模拟)

    /*
     * UVA_10930_1.cpp
     *
     *  Created on: 2013年10月7日
     *      Author: Administrator
     */
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    int K[30001];
    int main(){
    	int n;
    	int counter = 1;
    	while(scanf("%d",&n)!=EOF){
    
    		memset(K,0,sizeof(K));
    		int i,j;
    		printf("Case #%d:",counter++);
    		int w;
    		bool ok = true;
    		int last = 0;
    		K[0] = 1;//因为数字最小是从1开始的,所以将K[0]设为1,让0变为不可用
    		for(i = 1 ; i <= n ; ++i){
    			cin >> w;
    			cout<<" "<<w ;
    
    			ok &= !K[w] && w > last;
    
    			for(j = 10000 ; j >= w ; --j){
    				if(K[j - w]){
    					K[j] = 1;
    				}
    			}
    			last = w;
    		}
    		cout<<endl;
    
    		cout<<"This is "<< ((ok)?"":"not ") <<"an A-sequence.";
            cout<<endl;
    
    	}
    
    
    	return 0;
    }
    
    


  • 相关阅读:
    作业16
    递归函数
    三元表达式与生成式
    迭代器与生成器
    作业15
    装饰器
    作业14
    string的入门与进阶
    修理牧场(优先队列)
    旅游规划
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3356092.html
Copyright © 2011-2022 走看看