nyist 49 开心的小明(01背包)
来源:互联网 发布:js 设置控件不可用 编辑:程序博客网 时间:2024/04/30 12:23
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=49
思路:01背包
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x7f7f7f7f;//2139062143typedef long long ll;using namespace std;int dp[30010];int cost[30];int value[30];int main(){ int t; int n,m; int b; scanf("%d",&t); while(t--) { memset(dp,0,sizeof(dp)); scanf("%d%d",&n,&m); for(int i=0; i<m; i++) { scanf("%d%d",&cost[i],&b); value[i] = cost[i] * b; } for(int i=0; i<m; i++) { for(int j=n; j>=cost[i]; j--) { dp[j] = max(dp[j],dp[j-cost[i]] + value[i]); } } printf("%d\n",dp[n]); } return 0;}
0 0
- nyist 49 开心的小明(01背包)
- NYOJ 题目49 开心的小明 (01背包)
- NYOJ 题目49开心的小明(01背包)
- nyoj 开心的小明 49 (01背包)
- nyoj 49 开心的小明(01背包)
- NYOJ 49 开心的小明(01背包)
- 开心的小明-01背包
- 01背包,开心的小明
- nyoj49 开心的小明 01背包
- NYOJ 49-开心的小明:01背包
- nyoj 49 开心的小明 【DP】【01背包】
- NYOJ 49 开心的小明(01背包问题)
- NYOJ 49 开心的小明(0-1背包)
- NYOJ 49 开心的小明(0-1背包)
- nyoj--49--开心的小明(背包)
- 开心的小明(南阳oj49)(01背包)
- nyoj49开心的小明(01背包)
- NYoj49开心的小明(01背包)
- .NET Task的新认识
- 数据库常考笔试题
- 626B-Cards
- Pentest - psmsf
- neuq oj 1050: 谭浩强C语言(第三版)习题6.6 C++
- nyist 49 开心的小明(01背包)
- web学习博客2016/2/20
- python的邮箱正则的一些改进
- String、StringBuffer与StringBuilder之间区别
- 好气,action死活取不到input中的值
- .Net中访问数据库学习笔记
- Linux常用命令大全
- Github 搭建 hexo (五)- 站点地图(sitemap.xml)
- noj 1081 组织集体活动