/*
ID:kevin_s1
PROG:stamps
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath>
using namespace std;
#define MAXN 55
#define MAXK 205
#define MAXV 2000000
//gobal variable====
int K, N;
int stamps[MAXN];
int hash[MAXV];
int result;
//==================
//function==========
void DFS(int i, int sum){
if(i == K)
return;
for(int j = 1; j <= N; j++){
int tmp = sum + stamps[j];
hash[tmp] = 1;
DFS(i + 1, tmp);
}
return;
}
//==================
int main(){
freopen("stamps.in","r",stdin);
freopen("stamps.out","w",stdout);
cin>>K>>N;
for(int i = 1; i <= N; i++){
cin>>stamps[i];
}
memset(hash, 0, sizeof(hash));
sort(stamps + 1, stamps + N + 1);
DFS(0, 0);
for(int i = 1; i < MAXV; i++){
if(hash[i] == 0){
result = i - 1;
break;
}
}
cout<<result<<endl;
return 0;
}
USACO stamps TLE code
最新推荐文章于 2018-09-12 02:27:25 发布
本文探讨了一个经典的邮票组合问题,通过深度优先搜索(DFS)算法找出使用给定面额邮票所能达到的最大连续值。文章详细介绍了算法实现过程,并展示了如何避免重复计算以及如何确定最终结果。
396

被折叠的 条评论
为什么被折叠?



