题目1152:点菜问题
来源:互联网 发布:js函数内定义全局变量 编辑:程序博客网 时间:2024/05/17 05:00
#include "iostream"#include "stdio.h"#include <vector>#include <cstring>#include <algorithm>#include <string>#include <string.h>#include <stack>#include <ctype.h>#include <functional>#include <math.h>using namespace std;//1152 一维数组int dp[1010];int p[101],g[101];int c,n;int main(){ //freopen("input.txt","r",stdin); while(cin>>c>>n){ memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) cin>>p[i]>>g[i]; for(int i=1;i<=n;i++) for(int j=c;j>=p[i];j--) dp[j]=max(dp[j],dp[j-p[i]]+g[i]); cout<<dp[c]<<endl; } return 0;}/************************************************************** Problem: 1152 User: cust123 Language: C++ Result: Accepted Time:10 ms Memory:1524 kb****************************************************************/
#include "iostream"#include "stdio.h"#include <vector>#include <cstring>#include <algorithm>#include <string>#include <string.h>#include <stack>#include <ctype.h>#include <functional>#include <math.h>using namespace std;//1152int dp[101][1010];struct E{ int p,g;}E[101];int c,n;int main(){ //freopen("input.txt","r",stdin); while(cin>>c>>n){ memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) cin>>E[i].p>>E[i].g; for(int i=1;i<=n;i++){ for(int j=c;j>=E[i].p;j--) dp[i][j]=max(dp[i-1][j],dp[i-1][j-E[i].p]+E[i].g);\ for(int j=E[i].p-1;j>=0;j--) dp[i][j]=dp[i-1][j]; } cout<<dp[n][c]<<endl; } return 0;}/************************************************************** Problem: 1152 User: cust123 Language: C++ Result: Accepted Time:10 ms Memory:1920 kb****************************************************************/
0 0
- 题目1152:点菜问题
- 题目1152:点菜问题
- 题目1152:点菜问题
- 题目1152:点菜问题
- 九度oj 题目1152 点菜问题
- 九度OJ 题目1152:点菜问题
- 1152_点菜问题
- 点菜问题
- 另外一道题目:点菜
- 九度oj-1152-点菜问题
- 九度OJ - 1152 - 点菜问题
- OJ_1152 点菜问题
- poj 3714:点菜问题
- 点菜问题_1152
- 北大点菜问题
- 九度OJ 1152:点菜问题 (01背包、DP)
- 点菜
- 点菜文化
- opengl光照模型
- 矩阵卷积
- 置顶
- HTML5第六课时,float浮动影响的消除,clear
- 使用jquery mobile 创建页面
- 题目1152:点菜问题
- gdb常用命令
- php7 安装memcached 扩展 & centos 安装memceche
- 计算机启动过程
- 微服务和大数据相关的一些笔记
- 加速访问基于 Github Pages 和 Hexo 的博客
- MyBatis Generator 详解
- swing创建菜单
- 纯C正则