回忆的碎片
总提交 : 92 测试通过 : 9
描述
打完最后一场区域赛,A君回想起这四年在民大的ACM历程,感慨颇多。哭过,笑过,放弃过,奋斗过,一路奔跑,书写青春。这天,A君找来了N张记录自己这四年来在民大ACM奋斗的照片。比如:第一次打BC时的紧张表情;深夜十二点半打CF时的专注身影;查出一个困扰自己几天的bug时的狂喜……。对于这N张照片,每张照片都有一个幸福值a。A君能任意选择其中的几张(最少选一张)来拼凑成一个画面B,这个画面B能给A君带来幸福值C(C的值即为用来拼凑出画面B的照片的幸福值的总和)。现在,机智的你能帮A君算算他所不能拼凑出的最小的幸福值C是多少吗(C为正整数)?
输入
本题为多组数据评测。
第一行一个整数T(1≤T ≤10),表示测试组数。
对于每组测试数据:
第一行一个整数N(1 ≤ N ≤ 100),表示有N张照片。
第二行N个数A1 , A2 , …… AN,表示每张照片的幸福值.(1 ≤ Ai ≤100.)
输出
输出共T行,表示每组测试数据的答案。
对于每组测试数据,输出“Case #x: y”, x表示数据组数,y表示A君所不能拼凑出的最小的幸福值C(C为正整数)。
样例输入
3
4
2 3 4 5
5
1 2 3 4 5
4
1 2 4 5
样例输出
Case #1: 1
Case #2: 16
Case #3: 13
提示
对于第一组测试数据,A君能拼凑出的最小幸福值为2,所以他不能拼凑出的最小幸福值为1。
对于第二组测试数据,A君能拼凑出的幸福值为[1, 15]。所以他不能拼凑出的最小幸福值为16、
对于第三组测试数据,A君能拼凑出的幸福值为[1, 12]。所以他不能拼凑出的最小幸福值为13。
代码:
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include<functional>
#define INF 0xfffffff
#define eps 1e-6
#define LL long long
using namespace std;
const int maxn=1e3+5;
const int maxx=1e4+5;
const double q = (1 + sqrt(5.0)) / 2.0; // 黄金分割数
/*
std::hex <<16进制 cin>>std::hex>>a>>std::hex>>b
cout.setf(ios::uppercase);cout<<std::hex<<c<<endl;
b=b>>1; 除以2 二进制运算
//f[i]=(i-1)*(f[i-1]+f[i-2]); 错排
/ for (int i=1; i<=N; i++)
for (int j=M; j>=1; j--)
{
if (weight[i]<=j)
{
f[j]=max(f[j],f[j-weight[i]]+value[i]);
}
}
priority_queue<int,vector<int>,greater<int> >que3;//注意“>>”会被认为错误,
priority_queue<int,vector<int>,less<int> >que4;最大值优先
//str
//tmp
//vis
//cas
//val
//cnt 2486
*/
int main()
{
int n;
cin>>n;
int c[maxx],vis[maxx];
int cas=1;
while(n--)
{
int m,x;
cin>>m;
int len=0;
c[len++]=0;
memset(vis,0,sizeof(vis));
for(int i=0;i<m;i++)
{
cin>>x;
int s=len;
for(int j=0;j<s;j++)
{
int tmp=c[j]+x;
if(!vis[tmp])
{
vis[tmp]=1;
c[len++]=tmp;
}
}
}
for (int i = 1; ; i++) {
if (!vis[i]) {
printf("Case #%d: %d\n", cas++, i);
break;
}
}
}
}