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 ...
随机推荐
- 三级联动(ajax同步)
html <div id="frame"></div> js $(function(){ //拼接省市区下拉框 var str = `<select ...
- 2019Pycharm激活方法
1.将“0.0.0.0 account.jetbrains.com”添加到hosts文件中 2.打开http://idea.lanyus.com/ 3.获取激活码,粘贴到第二个选项中 亲测可用.
- (转载)Android平台下利用zxing实现二维码开发
Android平台下利用zxing实现二维码开发 现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研究了下二维码开发的东西,开源的二维码扫描库主要有zxing和zbar,zbar在iPos平 ...
- JS 判断中英文字符长度
function strlen(str) { var len = 0; for (var i = 0; i < str.length; i++) { ...
- 一、数组---数组中的K-diff数对※※※※※
给定一个整数数组和一个整数 k, 你需要在数组里找到不同的 k-diff 数对.这里将 k-diff 数对定义为一个整数对 (i, j), 其中 i 和 j 都是数组中的数字,且两数之差的绝对值是 k ...
- S-T表学习笔记
$O(nlogn)$构造$O(1)$查询真是太强辣 然而不支持修改= = ShØut! #include<iostream> #include<cstring> #includ ...
- ProGuard常见问题及解决套路
ProGuard是一个压缩.优化和混淆Java字节码的工具,非常好用.本篇文章总结一下许多人在使用ProGuard时经常遇到的问题. 我把在使用ProGuard时经常遇到的问题分为两类,分别是导致构建 ...
- 编辑距离Edit Distance 非常典型的DP类型题目
https://leetcode.com/problems/edit-distance/?tab=Description 真的非常好,也非常典型. https://discuss.leetcode.c ...
- Android体验高扩展艺术般的适配器
前言 本篇文章带大家体验一下一种具有扩展性的适配器写法. 这个适配器主要用于Item有多种的情况下.当然仅仅有一种类型也是适用的 实现 毫无疑问我们要继承BaseAdapter,重写getCount, ...
- programming-challenges Shoemaker's Problem (110405) 题解
Greedy. 证明: Let's say we have job 1, 2, ..., n, and they have time and fine as t1, f1, t2, f2, ..., ...