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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/399018.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Docker快速入门实践-纯干货文章

Docker快速入门实践-老男孩高级架构师课程内容&#xff0c;如果细看还能发现讲解视频呦&#xff01;小伙伴们赶紧猛戳吧&#xff01;老男孩高级架构师内部学员实践文档分享&#xff01;Docker快速入门实践-纯干货文章老男孩教育2016启用最新的官方博文地址&#xff1a;http://b…

180102

https://pan.baidu.com/s/1nvqYFt3转载于:https://www.cnblogs.com/wjy123/p/8175593.html

oracle的iw算法,[转载]Oracle日期周详解IW

1 ORACLE中周相关知识描述1.1 日期格式化函数TO_CHAR(X [,FORMAT])&#xff1a;将X按FORMAT格式转换成字符串。X是一个日期&#xff0c;FORMAT是一个规定了X采用何种格式转换的格式字符串&#xff0c;FORMAT与周相关的有W&#xff0c;WW&#xff0c;IW&#xff0c;D&…

spring3 常见异常解决

初学spring&#xff0c;在网上搜到一篇spring3常见异常的文章&#xff0c;现转载如下&#xff1a; 以下异常使用的是spring是3.1.1&#xff0c;是我自己学习中遇到的错误笔记&#xff0c;有可能不是都适用&#xff0c;仅做参考 异常1&#xff1a;java.lang.NoClassDefFoundErro…

git忽略某个文件夹

data/cache/* !data/cache/index.html !data/cache/smiOAuthToken.php 转载于:https://www.cnblogs.com/xiaobiaomei/p/8177168.html

Iterm2的一些好用法

今天把mac带到公司办公了&#xff0c;爽歪歪啊。 1&#xff0c;如何脱离鼠标拷贝屏幕中的内容 1) Commandf 调出选择框&#xff0c;并在其中输入要复制的字符&#xff0c;可以使用Tab补全 2) 按 Command c复制字符 3) 字符已经复制到剪切板了

记录一些容易忘记的属性 -- UITabBarController

UIViewController中的 property(nonatomic,copy) NSString *title; // Localized title for use by a parent controller.&#xff0c;仔细理解英文注释的意思 下面是Title的实际作用 //创建给分栏控制器使用的视图控制器(包括导航控制器) FirstViewController *firstVC …

LINQ to Tree - A Generic Technique for Querying Tree-like Structures,包含遍历WPF VisualTree

https://www.codeproject.com/Articles/62397/LINQ-to-Tree-A-Generic-Technique-for-Querying-Tree#generic 转载于:https://www.cnblogs.com/sjqq/p/8177276.html

在 ASP.NET MVC 3 中应用 KindEditor

http://www.cnblogs.com/weicong/archive/2012/03/31/2427608.html 第一步 将 KindEditor 的源文件添加到项目中&#xff0c;建议放到 /Scripts/kindeditor 目录中&#xff0c;其中只需要有 lang目录、plugis目录、themes目录和kindeditor-min.js文件即可。 第二步 在 /Views/S…

php phalcon.dll 下载,extension=php_phalcon.dll 安装过程

到phalcon官方网站下载对应的dll文件 phalcon_x86_VC9_php5.4.0_1.2.5 我下的是这个版本 所以用的wamp版本的php也是 php 5.4版本&#xff1b;所以没啥问题&#xff01;3&#xff1a;下载完了dll文件放在 刚安装好的wamp服务器下&#xff1a;因为我安装的是D盘&#xff1a;D:\w…

centOS配置国内镜像

本文以163为例&#xff0c; cd /etc/yum.repos.d/wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 转载于:https://www.cnblogs.com/azhqiang/p/8177408.html

浅谈https(创建、传输、断开)

前言 比起http&#xff0c;https是更安全的&#xff0c;传输过程中加密的。但是具体的加密过程是怎么样我一直一知半解。花了点时间抓包简单分析了一下&#xff0c;希望对大家有用。 在windows平台下抓tcp包是用wireshark的了。没啥好说的。   我们平常的一次https 的请求&am…

暑期项目经验(九) -- request session application

request、session、application 一、基础知识 可以看看 浅谈&#xff1a;request&#xff0c;session&#xff0c;application (http://blog.csdn.net/hzc543806053/article/details/7416007) 要点&#xff1a; 作用域&#xff1a; request<session<application 共同方法…

oracle 还原dmp时_报错的值太大,基于oracle数据库的CLOUD备份恢复测试

CLOUD oracle数据库备份恢复测试强烈建议使用expdp/impdp&#xff0c;因为&#xff1a;在expdp的时候Oracle不会再依赖和参考NLS_LANG的设置&#xff0c;而是完全按照数据库本身的字符集导出数据&#xff0c;impdp的时候&#xff0c;Oracle会自动判断如果dmp文件中的字符集和目…

Servlet读取文件的最好的方式

在java web 开发的时候不可避免的会读取文本信息&#xff0c;但是方式不同&#xff0c;所付出的代价也是不一样的&#xff0c;今天学到了一个比较好的实用性的技巧&#xff0c;拿来与大家分享一下。 读取属性配置文件 之所以说成是读取属性&#xff08;properties)文件&#xf…

Form.php 日期表单,Bootstrap日期和时间表单组件使用方法

提取其中的主要文件js/bootstrap-datetimepicker.js和css/bootstrap-datetimepicker.min.css1.引入bootstrap.min.css&#xff0c;因為其樣式包含在此文件中2.引入jquery.js&#xff0c;因為bootstrap是依賴於jquery的3.引入bootstrap.min.js以上是必備內容4.引入日期組件的css…

amp; 的意思

&amp是什么意思? <bean> <property name"jdbcUrl" value"jdbc:mysql://127.0.0.1:3306/spring?useUnicodetrue&amp;characterEncodingutf8"> </property> </bean> 这里面的&amp;是什么意思? 解答&#xff1a; &…

Bootstrap 排版

2019独角兽企业重金招聘Python工程师标准>>> Bootstrap 使用 Helvetica Neue、 Helvetica、 Arial 和 sans-serif 作为其默认的字体栈。 使用 Bootstrap 的排版特性&#xff0c;您可以创建标题、段落、列表及其他内联元素。 标题 Bootstrap 中定义了所有的 HTML 标题…

基于小波包的图像压缩及matlab实现,基于小波包的图像压缩及matlab实现精选.doc...

基于小波包的图像压缩及matlab实现精选基于小波包的图像压缩及matlab实现摘要&#xff1a;小波包分析理论作为新的时频分析工具&#xff0c;在信号分析和处理中得到了很好的应用&#xff0c;它在信号处理、模式识别、图像分析、数据压缩、语音识别与合成等等许多方面都取得了很…