多重背包
2016-05-25 17:10
281 查看
#include<iostream> #include<stdio.h> #include<cmath> #include<algorithm> #include<string> #include<cstring> #include<string.h> #include<map> #include<queue> #include<stack> #include<list> #include<cctype> #include<fstream> #include<sstream> #include<iomanip> #include<set> #include<vector> #include<cstdlib> #include<time.h> using namespace std; #define mem(x) memset(x,0,sizeof(x)) #define scanfd(x) scanf("%d",&x) struct node { int pice; int cnt; }d[105]; int dp[100005]; int main() { int i, j, k; int zong, n; int t; while (cin >> zong >> n) { mem(dp); for (int i = 1; i <= n; i++) { cin >> d[i].cnt >> d[i].pice; } int max = 0,tem; dp[0] = 1; for (int i = 1; i <= n; i++) { for (int k = max; k >= 0; k--) { if (dp[k]) for (int j = 1; j <= d[i].cnt; j++) { tem = k + j*d[i].pice; if (tem > zong) continue; dp[tem] = 1; if (tem > max) max = tem; } } } cout << max << endl; } return 0; }
相关文章推荐
- 第13周阅读程序——虚析构函数
- HDU 5691 状压dp
- Android 同步网络时间
- MQ基础
- 面试题目——《剑指Offer》
- NSOperationQueue
- 请求编码与响应编码
- Java 多态的主板示例
- 蓝牙4.0
- iOS 添加翼支付打包上传出错 ERROR ITMS-90535
- Volley的基本用法 使用Volley加载网络图片
- android studio如何导包
- Android ColorState使用
- 普通字符串转MFC字符串函数
- Intent传值的使用
- 设计模式 - Strategy模式
- Android Studio导入银联sdk
- 高斯遥感稳像的论文
- NSOperation
- NSThread