poj 3628 Bookshelf 2
2011-07-22 19:57
141 查看
#include <iostream> #include <algorithm> #include <functional> using namespace std; int arr[25],s,n,b,shelf[20000005]; void dfs(int i) { s+=arr[i]; shelf[s]=1; if(s==b) return ; else if(s>b) s-=arr[i]; else { for(int j=i+1;j<n;++j) { dfs(j); if(s==b) return ; } s-=arr[i]; } } int main() { cin>>n>>b; for(int i=0;i<n;++i) cin>>arr[i]; sort(arr,arr+n,greater<int>()); for(int i=0;i<n;++i) { dfs(i); if(s==b) { cout<<"0\n";return 0; } } for(int i=b+1;;++i) if(shelf[i]==1) { cout<<i-b<<endl; break; } return 0; }
相关文章推荐
- poj 3628 Bookshelf 2(01背包)
- Bookshelf 2 POJ - 3628(01背包||DFS)
- POJ 3628 Bookshelf 2 0-1背包
- POJ 3628 Bookshelf 2
- POJ 3628 Bookshelf 2 DFS 0-1背包问题
- POJ 3628 Bookshelf 2
- poj 3628 - Bookshelf 2
- 简单01背包问题求解 POJ:3628 Bookshelf 2
- POJ 3628 Bookshelf 2 (01背包)
- POJ 3628 Bookshelf 2(DP:01背包)
- POJ 3628 - Bookshelf 2
- POJ 3628 Bookshelf 2 G++
- poj 3628 Bookshelf 2 01背包或者dfs
- POJ 3628 Bookshelf 2 0-1背包 or DFS 水题
- poj 3628 Bookshelf 2 01背包
- poj 3628 Bookshelf 2(01背包,dfs)
- POJ 3628 Bookshelf 2
- DP背包 或 搜索 poj 3628 Bookshelf 2
- poj 3628 Bookshelf 2 (0/1背包)
- poj 3628 Bookshelf 2 01背包!!!