当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
What's a good gift for your girlfriend on Chinese Valentine's day? Boys who can't give gifts, look!
[c语言]--一步一步实现扫雷小游戏
战疫杯--我的账本
OJ 1089 春运
气传导耳机哪个品牌比较好、这四款不要错过
气传导蓝牙耳机哪个好、气传导蓝牙耳机排行榜
Servlet
Getting started with hugging face
小程序:wsx脚本
Pyppeteer is recognized to bypass detection
小程序自定义组件-数据,方法和属性
Development of Quantitative Trading Robot System
[c语言]简易通讯录的实现
C语言的编译和预处理
【学习笔记】工具
自定义组件--插槽
[PTA----树的遍历]
Explain the installation of MSDN 2015 and precautions
江中ACM新生10月26日习题题解
Icc2 use report_ Placement check floorplan









