WHU 1537 Stones I
这个题相当无语,学长给的解法是:枚举取的个数k,然后对每个k贪心,取其中的最大值。
我想思路应该是这样:结果与选取的顺序无关,只和最终选取的数量有关。
所以,就枚举最终选取的数量k,在这种情况下,每个物品的价值就是固定的。
所以,在这种情况下,最优策略就一定是选取价值最大的前k个。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional> using namespace std; const int MAXN = ; int a[MAXN], b[MAXN], c[MAXN];
int n; int main() {
#ifdef Phantom01
freopen("WHU1537.txt", "r", stdin);
#endif // Phantom01 while (scanf("%d", &n)!=EOF) {
if (==n) break; for (int i = ; i < n; i++)
scanf("%d%d", &a[i], &b[i]);
int ans = ;
for (int k = ; k <= n; k++) {
for (int i = ; i < n; i++)
c[i] = a[i] - k*b[i];
sort(c, c+n, greater<int>());
int tmp = ;
for (int i = ; i < k; i++)
tmp += c[i];
ans = max(ans, tmp);
}
printf("%d\n", ans);
} return ;
}
WHU 1537 Stones I的更多相关文章
- WHU 1538 Stones II 动态规划
赛后写的,动态规划,学长和题解,提供了两种状态设计的思路,都写了下……结果在写第二种的时候,不小心把下标的起点写错了,导致WA了无数发…… 无奈啊……每次都是这种错误…… 题意: 大概就是有n块石头, ...
- whu Problem 1537 - A - Stones I 贪心
题目链接: http://acm.whu.edu.cn/land/problem/detail?problem_id=1537 Stones I Time Limit: 1000MSMemory Li ...
- whu 1538 - B - Stones II 01背包
题目链接: http://acm.whu.edu.cn/land/problem/detail?problem_id=1538 Problem 1538 - B - Stones II Time Li ...
- WOJ 1538 B - Stones II
Problem 1538 - B - Stones IITime Limit: 1000MS Memory Limit: 65536KB Total Submit: 416 Accepted: 63 ...
- bzoj 1537: [POI2005]Aut- The Bus 线段树
bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][ ...
- 51nod-1537 1537 分解(矩阵快速幂+找规律)
题目链接: 1537 分解 问(1+sqrt(2)) ^n 能否分解成 sqrt(m) +sqrt(m-1)的形式 如果可以 输出 m%1e9+7 否则 输出no Input 一行,一个数n.( ...
- HDU 5973 Game of Taking Stones 威佐夫博弈+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5973 Game of Taking Stones Time Limit: 2000/1000 MS ...
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- codechef Jewels and Stones 题解
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery acces ...
随机推荐
- C# 运算符 ?、??、?: 、?. 、 各种问号的用法和说明
1. 可空类型修饰符(?):引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; 是正确的,int i=null; 编译器就会报错.为了使值类型也 ...
- EL与JSTL学习(二)——JSTL技术
1.JSTL概述 JSTL(JSP Standard Tag Library),JSP标准标签库,可以嵌入在jsp页面中使用标签的形式完成业务逻辑等功能. jstl出现的目的同el一样也是要代替jsp ...
- 【原创】不重启was server重新加载应用class文件
类装入和更新检测(Class loading and update detection settings)菜单路径:Applications < Application Types < W ...
- jsp表单验证格式
- React-Router-API中文介绍
React-Router API 以下内容翻译自react-router/doc/API.md,方便使用时查看,之前的学习都是能够工作即可,但一些内在发生的行为并不知晓,借此理解一番: ##Compo ...
- express + multer 文件上传入门
写在前面的 在web开发中,我们经常会遇到图片上传的功能,接下来我们就在express4.15.0框架中利用multer1.3.0模块来实现图片上传 开始敲代码 首先利用express-generat ...
- Url 简单讲解
eg: http://sb.test.com/login?name=liming&password=twotigers 协议 http https ftp 域名 sb.test.com 则是域 ...
- 浏览器解析,HTTP/HTTPS、TCP/IP、WebSocket协议
浏览器相关 浏览器对同一个域名有连接数限制,大部分是 6. 浏览器指的是 Chrome.Firefox,而浏览器内核则是 Blink.Gecko,浏览器内核只负责渲染,GUI 及网络连接等跨平台工作则 ...
- 一线 | 中国联通宣布首批5G手机到位
腾讯<一线> 作者郭晓峰 据中国联通相关人士今日透露,中国联通用于 5G 友好体验的首批合作 5G 手机全部到位.有 12 个品牌共 15 款 5G 手机及 5G CPE,包括.华为. O ...
- UT源码+105032014018
设计佣金问题的程序 commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone).手机壳(Mobile phone shell).手机贴膜(Cellphon ...