poj 1384 piggy-bank
来源:互联网 发布:网络营销优化方案 编辑:程序博客网 时间:2024/05/18 18:14
#include<iostream>#include<fstream>#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;const int MAX = 0x6fffffff;int t,e,f,n,net, m;struct coin{int p;int w;};int c[10010];int main(){//freopen("1.txt","r",stdin);scanf("%d",&t);while(t--){scanf("%d%d%d",&e,&f,&n);net = f - e;m = net + 1;memset(c,0,sizeof(c));for(int i = 0; i <= m; ++i){c[i] = MAX;}coin * pig = new coin[n+1];memset(pig,0,(n+1)*4);for(int i = 1; i <= n; ++i){scanf("%d%d",&pig[i].p,&pig[i].w);}for(int i = 1;i <= n; ++i){c[0] = 0;for(int j = pig[i].w; j <= net; ++j){if(c[j-pig[i].w] + pig[i].p < c[j]){c[j] = c[j-pig[i].w] + pig[i].p;}}}if(c[net] == MAX){printf("This is impossible.\n");}else{printf("The minimum amount of money in the piggy-bank is %d.\n",c[net]);}}return 0;}
Key:
每次循环时c[0]记得初始化~
- poj 1384 Piggy-Bank
- poj 1384 Piggy-Bank
- POJ 1384 Piggy-Bank
- poj 1384 piggy-bank
- POJ 1384 Piggy-Bank
- POJ 1384 Piggy-Bank
- poj 1384 Piggy-Bank
- POJ 1384 Piggy-Bank
- poj 1384 Piggy-Bank
- POJ 1384 Piggy-Bank
- POJ 1384 Piggy-Bank
- POJ 1384 Piggy-Bank
- POJ 1384 Piggy-Bank DP
- POJ 1384 Piggy-Bank 笔记
- POJ 1384 Piggy-Bank (ZOJ 2014 Piggy-Bank) 完全背包
- poj 1384 Piggy-Bank 完全背包
- poj 1384Piggy-Bank(完全背包)
- POJ 1384 Piggy-Bank (完全背包)
- Fedora9下Seismic Unix地震数据处理系统(SU)安装
- Android Button
- 关于我
- ubuntu13.04 编译环境
- crtmpserver笔记之文档结构
- poj 1384 piggy-bank
- [xxx objectForKey:]: unrecognized selector sent to instance 错误的另类原因
- 【让Win7发挥极限快速关机】
- 加速Java应用开发速度2——加速项目调试启动速度
- 八皇后问题、N皇后问题回溯法详解
- ttyS 和 ttyO 的区别
- SecureCRT登录freebsd时tab不能自动补齐
- ZBarSDK支持armv7s
- 代码问题讨论