日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces 176A Trading Business 贪心

發布時間:2023/11/29 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces 176A Trading Business 贪心 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Trading Business

題目連接:

http://codeforces.com/problemset/problem/176/A

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<bits/stdc++.h> 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<<ans<<endl; }

總結

以上是生活随笔為你收集整理的CodeForces 176A Trading Business 贪心的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。