博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 176A Trading Business 贪心
阅读量:4971 次
发布时间:2019-06-12

本文共 3305 字,大约阅读时间需要 11 分钟。

Trading Business

题目连接:

Description

To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.

The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following:

aij — the cost of buying an item;

bij — the cost of selling an item;

cij — the number of remaining items.

It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind.

Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get.

Input

The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 10, 1 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.

Then follow n blocks describing each planet.

The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≤ bij < aij ≤ 1000, 0 ≤ cij ≤ 100) — the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces.

It is guaranteed that the names of all planets are different.

Output

Print a single number — the maximum profit Qwerty can get.

Sample Input

3 3 10

Venus

6 5 3

7 6 5

8 6 10

Earth

10 9 0

8 6 4

10 9 3

Mars

4 3 0

8 4 12

7 2 5

Sample Output

16

Hint

题意

有n个星球,然后每个星球有m个商品,买需要ai元,卖需要bi元,只有ci个

你需要在一个星球买最多k个商品,然后在一个星球卖出去

问你最多赚多少钱

题解:

暴力枚举在哪个星球买,在哪个星球卖

然后直接贪心的去选择k个商品就好了

选择差价最大的k个商品

代码

#include
using namespace std;int a[20][200];int b[20][200];int c[20][200];int vis[200];int n,m,k;int solve(int x,int y){ memset(vis,0,sizeof(vis)); int last = k; int ans = 0; while(last) { int flag = 0; int Max=0,Maxc=0; for(int i=1;i<=m;i++) { if(vis[i])continue; if(b[y][i]-a[x][i]>Max) { Max=b[y][i]-a[x][i]; Maxc=i; flag=1; } } if(!flag)break; int num = min(last,c[x][Maxc]); ans += num*Max; vis[Maxc]=1; last-=num; } return ans;}int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++) { string s; cin>>s; for(int j=1;j<=m;j++) scanf("%d%d%d",&a[i][j],&b[i][j],&c[i][j]); } int ans = 0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { ans=max(ans,solve(i,j)); } cout<
<

转载于:https://www.cnblogs.com/qscqesze/p/5146232.html

你可能感兴趣的文章
java if 用法详解_Java编程中的条件判断之if语句的用法详解
查看>>
matlab sin函数 fft,matlab的fft函数的使用教程
查看>>
mysql adddate()函数
查看>>
mysql sin() 函数
查看>>
mysql upper() 函数
查看>>
单片机复位电路
查看>>
php json_decode失败,返回null
查看>>
3-day3-list-truple-map.py
查看>>
Edit控件显示多行文字
查看>>
JS第二周
查看>>
dataTable.NET的search box每輸入一個字母進行一次檢索的問題
查看>>
Python 文件处理
查看>>
邻接表详解
查看>>
迭代dict的value
查看>>
eclipse package,source folder,folder区别及相互转换
查看>>
Py 可能是最全面的 python 字符串拼接总结(带注释版)
查看>>
《Java程序设计实验》 软件工程18-1,3 OO实验2
查看>>
【Herding HDU - 4709 】【数学(利用叉乘计算三角形面积)】
查看>>
OPENSSL使用方法
查看>>
接口操作XML
查看>>