题目见: 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. IEEE Access的模板的问题

    这个模板果然问题还是有一些,比如caption换行得自己改class文件.首先感谢一下CSDN的一位网友的经验https://blog.csdn.net/baidu_21381705/article/ ...

  2. (转载)带有res资源文件的项目 需要导成jar包 供别人使用的解决方法

    比如说自己的成品项目,名字是MyObject,需要导出成jar包,让别人的项目调用,但是自己的项目还包含有图片.layout布局.libs里面的依赖包等等: 步骤: 1.MyObject项目需要“is ...

  3. FCC高级编程篇之Exact Change

    Exact Change Design a cash register drawer function checkCashRegister() that accepts purchase price ...

  4. 拉格朗日插值&&快速插值

    拉格朗日插值 插值真惨 众所周知$k+1$个点可以确定一个$k$次多项式,那么插值就是通过点值还原多项式的过程. 设给出的$k+1$个点分别是$(x_0,y_0),(x_1,y_1),...,(x_k ...

  5. ansible搭建mysql主主模式

    ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)等优点,实现了批量系统配置.批量程序部署.批量运行命 ...

  6. thymeleaf 拼接 超链接

    <dd><a th:href="@{/get/{id}(id=${user.id})}">基本资料</a></dd>

  7. HDU 2782 The Worm Turns (DFS)

    Winston the Worm just woke up in a fresh rectangular patch of earth. The rectangular patch is divide ...

  8. 基于SpringMVC+Bootstrap+DataTables实现表格服务端分页、模糊查询

    前言 基于SpringMVC+Bootstrap+DataTables实现数据表格服务端分页.模糊查询(非DataTables Search),页面异步刷新. 说明:sp:message标签是使用了S ...

  9. 使用sh运行bash脚本的奇怪问题

    在同一个文件夹下有两个脚本.a.sh和b.sh,脚本内容例如以下: a.sh: echo "test for a" source b.sh b.sh: echo "tes ...

  10. [MST] Store Store in Local Storage

    For an optimal user and developer experience, storing state in local storage is often a must. In thi ...