poj 1293 Duty Free Shop
来源:互联网 发布:你知我所想我知你所要 编辑:程序博客网 时间:2024/06/06 12:22
真可谓是wrong了一地, 如果有和我一样的,我可以提供点参考点。
我错的地方是, 没考虑到m可以一个都不放进盒子里
比如这组数据
1 10
5
2 2 2 2 2
这时m一个也不需要,所有的盒子全部用来放l, 所以此时的输出时0, 哎,伤心啊。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int Maxn = 2010;int m, l, n, sum, ans;int v[Maxn];bool dp[Maxn];int path[Maxn];void fint(int x) { ans += 1; if(x - v[path[x]] == 0) { cout<<ans<<" "<<path[x]; return; } else { fint(x - v[path[x]]); cout<<" "<<path[x]; }}void solve() { ans = 0; memset(path, 0, sizeof(path)); memset(dp, false, sizeof(dp)); int ma = 0; dp[0] = true; for(int i = 1; i <= n; ++i) { ma += v[i]; if(ma > m) ma = m; for(int j = ma; j >= v[i]; j--) { if(dp[j - v[i]]&&!dp[j]) { dp[j] = true; path[j] = i; } } } int k = m; while(!dp[k]) k--; if((sum - k) > l) cout<<"Impossible to distribute"<<endl; else { if(k == 0) cout<<0; else fint(k); cout<<endl; }}int main(void){ while(scanf("%d%d",&m,&l), m||l) { sum = 0; scanf("%d",&n); for(int i = 1; i <= n; ++i) { scanf("%d",v+i); sum += v[i]; } solve(); } return 0;}
0 0
- poj 1293 Duty Free Shop
- poj 1293 Duty Free Shop
- poj 1293 Duty Free Shop
- POJ 1293 Duty Free Shop
- Duty Free Shop - POJ 1293 dp
- POJ 1293 Duty Free Shop 笔记
- POJ 1293 Duty Free Shop(背包记录路径)
- POJ 1293 - Duty Free Shop 01背包记录所选物品
- zoj 1520 - Duty Free Shop
- zoj 1520 Duty Free Shop
- duty
- shop
- Shop++
- shop
- Oh, duty!
- POJ 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 LITTLE SHOP OF FLOWERS (DP)
- poj 1157 LITTLE SHOP OF FLOWERS
- nyoj_168 房间安排
- linux gdb调试命令小助手
- 初识GitHub
- Spark流处理(WordCount)
- HDU 1010(剪枝+深搜)
- poj 1293 Duty Free Shop
- crc64 redis 源码
- Algorithm学习笔记 --- 三角形求周长
- Transport (VMDB) error 44 Message
- 编译MT7620内核出现问题
- LeetCode之Binary Tree Inorder Traversal
- 第四周(项目四)——数组做数据成员。
- java 图标类Images - ImageIcon
- 关于RSA算法的例子实践(第二周作业)