POJ 3628 Bookshelf 2(背包)
2013-04-22 19:49
417 查看
刚开始看到题目发现数据竟然这么大,然后一直在找解决方法,最后竟然不用考虑,poj的数据很小.
太坑爹了.
太坑爹了.
#include <iostream> #include <cstdio> #include <memory.h> #include <algorithm> using namespace std; const int maxn=20000001; int dp[maxn],t[21],n,b; int main(){ while (scanf("%d%d",&n,&b)==2){ int maxv=0,s=0; for (int i=0;i<n;++i){ scanf("%d",&t[i]); s+=t[i]; } sort(t,t+n); for (int i=0;i<n;++i){ for (int j=s;j>=t[i];--j){ dp[j]=dp[j-1]; if(dp[j-1]<dp[j-t[i]]+t[i]){ dp[j]=dp[j-t[i]]+t[i]; } } } int ans=20000001; for (int i=0;i<=s;++i){ if(dp[i]>=b&&dp[i]-b<ans){ ans=dp[i]-b; } } printf("%d\n",ans); } }
相关文章推荐
- POJ 3628 Bookshelf 2 DFS 0-1背包问题
- POJ 3628 Bookshelf 2(DP:01背包)
- poj 3628 Bookshelf 2 背包
- POJ 3628 Bookshelf 2(0-1背包)
- Bookshelf 2 POJ - 3628(01背包||DFS)
- poj3628 Bookshelf 2(0/背包)
- Round 3 Bookshelf 2 POJ - 3628 -搜索(假背包)
- POJ 3628 Bookshelf 2(简单背包)
- poj 3628 Bookshelf 2(01背包入门或者dfs)
- poj 3628 Bookshelf 2 01背包
- DP背包 或 搜索 poj 3628 Bookshelf 2
- POJ 3628 Bookshelf 2 0-1背包 or DFS 水题
- POJ 3628 Bookshelf 2 0-1背包
- poj 3628 Bookshelf 2( 0-1背包。)
- POJ 3628 Bookshelf 2 0-1背包
- POJ 3628 Bookshelf 2 0/1背包和DFS两种解法
- POJ 3628 Bookshelf 2 0-1背包 or DFS 水题
- POJ-3628--Bookshelf 2--01背包
- poj 3628 Bookshelf 2(0/1背包)
- poj3628 Bookshelf 2 DP 01背包