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 贪心的更多相关文章

  1. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  2. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

  3. CodeForces Gym 100685I Innovative Business (贪心)

    题意:给定一条路的长和宽,然后给你瓷砖的长和宽,你只能横着或者竖着铺,也可以切成片,但是每条边只能对应一条边,问你最少要多少瓷砖. 析:先整块整块的放,然后再考虑剩下部分,剩下的再分成3部分,先横着, ...

  4. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  5. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  6. Codeforces 486C Palindrome Transformation(贪心)

    题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...

  7. Codeforces 1154D - Walking Robot - [贪心]

    题目链接:https://codeforces.com/contest/1154/problem/D 题解: 贪心思路,没有太阳的时候,优先用可充电电池走,万不得已才用普通电池走.有太阳的时候,如果可 ...

  8. codeforces 735C Tennis Championship(贪心+递推)

    Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C ——每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...

  9. CodeForces - 363D --二分和贪心

    题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...

随机推荐

  1. DzzOffice共享文件夹、共享目录设置

    dzzoffice中共享目录的设置,是通过机构部门建立的. 首先打开机构用户管理.建立需要的机构和部门.这里机构和部门可以理解为共享目录的名称.也可以根据自己需要起名,并不一定是机构和部门的名字. 而 ...

  2. javascript --- 面向对象 --- 封装

    javascript中有原型对象和实例对象 如有疑问请参考:http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_enca ...

  3. javascript中=、==、===区别详解

    javascript中=.==.===区别详解今天在项目开发过中发现在一个小问题.在判断n==""结果当n=0时 n==""结果也返回了true.虽然是个小问题 ...

  4. 【转】 Linux Shell 命令--rename

    重命名文件,经常用到mv命令,批量重命名文件rename是最好的选择,Linux的rename 命令有两个版本,一个是C语言版本的,一个是Perl语言版本的,判断方法:输入man rename 看到第 ...

  5. Embedded之memory test

    1 main.c #include "led.h" #define BASE_ADDRESS (volatile datum *) 0x10000000 #define NUM_B ...

  6. geeksforgeeks@ Minimum Points To Reach Destination (Dynamic Programming)

    http://www.practice.geeksforgeeks.org/problem-page.php?pid=91 Minimum Points To Reach Destination Gi ...

  7. SCAU 10893 Spiral

    10893 Spiral 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description Given an odd number n, we can ar ...

  8. nodejs 基本操作

    查看nodejs版本 nodejs -v 升级nodejs node有一个模块叫n(这名字可够短的...),是专门用来管理node.js的版本的.首先安装n模块:npm install -g n 第二 ...

  9. 阿里云开放服务oss的api

    http://imgs-storage.cdn.aliyuncs.com/help/oss/OSS_API_20131015.pdf?spm=5176.383663.5.23.JQjiIK&f ...

  10. php基础知识(1)

    1.判断变量是否存在isset() $v1="a"; if(!isset($v1)){ echo "变量存在"; }else{ echo "变量不存在 ...