当前位置:网站首页>OJ 1253 ordering problem
OJ 1253 ordering problem
2022-07-28 06:38:00 【JETECHO】
describe
PKU network laboratory often has activities that need to be bought out , However, the maximum amount of reimbursement expenses for each call out is C element , Yes N Grow vegetables and order , After a long order , Web lab for every dish i There is a quantitative evaluation score ( It means how delicious this dish is ), by Vi, The price of each dish is Pi, Ask how to choose a variety of dishes , So that the total evaluation score of the dishes ordered can be maximized within the reimbursement limit .
Be careful : Due to the need for nutritional diversity , Each dish can only be ordered once .
Input
The first line of input has two integers C(1 <= C <= 1000) and N(1 <= N <= 100),C Represents the total amount that can be reimbursed ,N> Represents the number of dishes you can order . Next N Each line consists of two in 1 To 100 Between ( Include 1 and 100) The whole number of , They represent the of the dish > Price and evaluation score of dishes .
Output
The output consists of only one line , This line contains only one integer , Means within the reimbursement limit , The maximum evaluation score of the dish ordered .
sample input 1
1 3
1 5
3 3
2 5
24 8
2 9
8 6
4 1
1 4
2 2
10 5
2 1
1 4
sample output 1
5
30
The topic requires to find out the maximum order value , Dynamic programming can be used , Select a value and recurse it .
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[100],b[100],dp[1001];
int main()
{
int c,n;
while(cin>>c>>n)
{
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
cin>>a[i]>>b[i];
for(int i=0;i<n;i++)
{
for(int j=c;j>=a[i];j--)
dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
}
cout<<dp[c]<<endl;
}
return 0;
}
边栏推荐
猜你喜欢

OpenGL quick configuration method

Leetcode 刷题日记 剑指 Offer II 053. 二叉搜索树中的中序后继

藏宝计划TPC系统开发Dapp搭建

气传导耳机哪个品牌比较好、这四款不要错过

2022-06-07 responsebodyadvice caused the spring frame problem in swagger

2021-11-10

小程序创建组件

Solve the problem that the memory occupation is higher than that of the application process

夹子套利/搬砖套利系统开发

万字归纳总结并实现各大常用排序及性能对比
随机推荐
关于Shader KeyWord的整理
ubuntu mysql 设置远程访问权限
ZOJ Problem 1005 jugs
【实现简易版扫雷小游戏】
2021-11-10
QT implementation outputs relevant information to log file
MySQL安装与使用
In vscade, the source file "adafruit_gfx.h" cannot be opened“
小程序自定义组件-数据,方法和属性
用c语言实现三子棋小游戏
execjs 调用
suger BI 创建任务
My notes
Pyppeteer 被识别 绕过检测
自定义组件--样式
STM32的IAP跳转相关bug经历
【动态规划--买卖股票的最佳时期系列2】
微信小程序自定义编译模式
Execjs call
[c语言]--一步一步实现扫雷小游戏