题目见: http://acm.whu.edu.cn/land/problem/detail?problem_id=1537

  这个题相当无语,学长给的解法是:枚举取的个数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的更多相关文章

  1. WHU 1538 Stones II 动态规划

    赛后写的,动态规划,学长和题解,提供了两种状态设计的思路,都写了下……结果在写第二种的时候,不小心把下标的起点写错了,导致WA了无数发…… 无奈啊……每次都是这种错误…… 题意: 大概就是有n块石头, ...

  2. whu Problem 1537 - A - Stones I 贪心

    题目链接: http://acm.whu.edu.cn/land/problem/detail?problem_id=1537 Stones I Time Limit: 1000MSMemory Li ...

  3. whu 1538 - B - Stones II 01背包

    题目链接: http://acm.whu.edu.cn/land/problem/detail?problem_id=1538 Problem 1538 - B - Stones II Time Li ...

  4. WOJ 1538 B - Stones II

    Problem 1538 - B - Stones IITime Limit: 1000MS Memory Limit: 65536KB Total Submit: 416 Accepted: 63 ...

  5. 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][ ...

  6. 51nod-1537 1537 分解(矩阵快速幂+找规律)

    题目链接: 1537 分解  问(1+sqrt(2)) ^n  能否分解成 sqrt(m) +sqrt(m-1)的形式  如果可以 输出 m%1e9+7 否则 输出no Input 一行,一个数n.( ...

  7. HDU 5973 Game of Taking Stones 威佐夫博弈+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5973 Game of Taking Stones Time Limit: 2000/1000 MS ...

  8. HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...

  9. codechef Jewels and Stones 题解

    Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery acces ...

随机推荐

  1. 内部div自动扩张剩余宽度

    <div id="container"> <div id="left">左边</div> <div id=" ...

  2. STM8S103之ADC

    如何快速了解ADC,查看Reference manual中ADC registers章节,初步了解到ADC ADC buffer register和ADC data register Analog W ...

  3. dispatch_group_t踩过的坑

    如果想在dispatch_queue中所有的任务执行完成后在做某种操作,在串行队列中,可以把该操作放到最后一个任务执行完成后继续,但是在并行队列中怎么做呢.这就有dispatch_group 成组操作 ...

  4. NodeJS学习笔记 (5)网络服务-http-req(ok)

    原文:https://github.com/chyingp/nodejs-learning-guide 自己敲代码: 概览 本文的重点会放在req这个对象上.前面已经提到,它其实是http.Incom ...

  5. NOIp2018模拟赛四十三

    有了昨天的经验,不慌,开题先看source ******** 再看看题,看到C题标题: ******** 有毒... B题的“显然”50分结论推了我一个小时,然后就弃疗了... 成绩:0+50+5=5 ...

  6. mysql中如何查看某个数据库或表占用的磁盘空间

    查整个库的状态:select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,          concat(tru ...

  7. /application/nginx/sbin/nginx -h

    [root@web03 ~]# /application/nginx/sbin/nginx -h nginx version: nginx/1.6.3Usage: nginx [-?hvVtq] [- ...

  8. Angular 快速上手

    本文系 Angular 快速上手学习笔记 安装 CLI npm install -g @angular/cli 创建工作空间和初始应用 ng new my-app 启动开发服务器 cd my-app ...

  9. java流与文件的操作 文件加密

    课后作业 1,源代码 import java.io.*; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttribu ...

  10. [LeetCode] 455. 分发饼干 assign-cookies(贪心算法)

    思路: 尽量先将小饼干分配给胃口小的孩子,故而饼干和孩子胃口都应该先排序. python中,a.sort()只能用于a为list, sort()是可变对象的方法,无参数,无返回值,但会影响改变对象. ...