Problem 1538 - B - Stones II
Time Limit: 1000MS Memory Limit: 65536KB
Total Submit: 416 Accepted: 63 Special Judge: No

Description
Xiaoming took the flight MH370 on March 8, 2014 to China to take the ACM contest in WHU. Unfortunately, when the airplane crossing the ocean, a beam of mystical light suddenly lit up the sky and all the passengers with the airplane were transferred to another desert planet.

When waking up, Xiaoming found himself lying on a planet with many precious stones. He found that:

There are n precious stones lying on the planet, each of them has 2 positive values ai and bi. Each time Xiaoming can take the ith of the stones ,after that, all of the stones’ aj (NOT including the stones Xiaoming has taken) will cut down bi units.

Xiaoming could choose arbitrary number (zero is permitted) of the stones in any order. Thus, he wanted to maximize the sum of all the stones he has been chosen. Please help him.
Input
The input consists of one or more test cases.

First line of each test case consists of one integer n with 1 <= n <= 1000.
Then each of the following n lines contains two values ai and bi.( 1<= ai<=1000, 1<= bi<=1000)
Input is terminated by a value of zero (0) for n.
Output
For each test case, output the maximum of the sum in one line.
Sample Input
1
100 100
3
2 1
3 1
4 1
0
Sample Output
100
6

解题:动态规划 dp[i][j]表示考察了前面i个 还要选j个

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF = 0x3f3f3f3f;
  4. const int maxn = ;
  5. struct stone{
  6. int a,b;
  7. bool operator<(const stone &rhs)const{
  8. return b < rhs.b;
  9. }
  10. }s[maxn];
  11. int dp[maxn][maxn];
  12. int main(){
  13. int n;
  14. while(scanf("%d",&n),n){
  15. memset(dp,-INF,sizeof dp);
  16. dp[][] = ;
  17. for(int i = ; i <= n; ++i){
  18. dp[][i] = ;
  19. scanf("%d%d",&s[i].a,&s[i].b);
  20. }
  21. sort(s+,s+n+);
  22. for(int i = ; i <= n; ++i)
  23. for(int j = ; j <= n; ++j)
  24. dp[i][j] = max(dp[i-][j],dp[i-][j+] + s[i].a - s[i].b*j);
  25. printf("%d\n",dp[n][]);
  26. }
  27. return ;
  28. }

WOJ 1538 B - Stones II的更多相关文章

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

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

  2. Problem 1538 - B - Stones II 贪心+DP

    还是给你石头n枚,每一枚石头有两个值a和b,每取一个石头,除了这块石头其余所有的石头的a就都减去这个石头的b,问你取了的石头的a的总和最大可以为多少? 先按B从大到小排序 然后DP: 取的话:dp[i ...

  3. WOJ 1538 Stones II 转化背包问题

    昨天是我负责这个题目的,最后没搞出来,真的给队伍拖后腿了. 当时都推出来了 我假设最后结果是取了m个物品,则我把这个m个物品按取的先后编号为 k1 k2 k3 k4...km 则最终结果就是 (k1. ...

  4. WHU 1538 Stones II 动态规划

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

  5. woj - 将一个问题转换为背包问题

    Problem 1538 - B - Stones II Time Limit: 1000MS   Memory Limit: 65536KB   Total Submit: 428  Accepte ...

  6. 【转载】ACM总结——dp专辑

    感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一 ...

  7. FZU1327 优先队列

    Problem 1327 Blocks of Stones II Accept: 318    Submit: 881Time Limit: 1000 mSec    Memory Limit : 3 ...

  8. 【DP专辑】ACM动态规划总结

    转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 ...

  9. dp专题训练

    ****************************************************************************************** 动态规划 专题训练 ...

随机推荐

  1. Android 线程 Looper.prepare()、Looper.loop() 使用

    优化项目过程中发现了一个非常Low的问题,整理一下.备忘: 说问题之前先看下HandlerThread的定义 一个封装了looper的线程:   Looper用于封装了android线程中的消息循环. ...

  2. Codeforces Round #277 (Div. 2)A. Calculating Function 水

    A. Calculating Function   For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 +  ...

  3. luogu2154 [SDOI2009] 虔诚的墓主人 离散化 树状数组 扫描线

    题目大意 公墓可以看成一块N×M的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地.一块墓地的虔诚度是指以这块墓地为中心的十字架的数目,一个十字架可以看成中间是墓地,墓地的正上.正 ...

  4. C# 正则表达式 和 JAVA表达式是想通的

    正则表达式语法 也许有人会说,现在需要正则表达式去验证什么的话,直接在网上找不久一大片吗?还需要学什么啊! 是的,现在在网上找确实是一找一大片,但是,有时候我们也遇到这样的情况,就是我们在网上找的复制 ...

  5. codeforces round #420 div2

    A:暴力枚举 模拟 #include<bits/stdc++.h> using namespace std; ; int n; int a[N][N]; int main() { scan ...

  6. C#发送电子邮件代码记录

    /// <summary> /// 发送电子邮件 /// </summary> /// <param name="Address">邮件地址&l ...

  7. golang 获取statuscode

    最近日志打印的时候需要打印状态码,但是因为interface的原因直接获取失败,http.Request里面的response不知道怎么使用,所以就自己重写writeheader,write来截取st ...

  8. C - Football

    Problem description Petya loves football very much. One day, as he was watching a football match, he ...

  9. word文档去掉复制过来的背景颜色

    选择清除格式

  10. CSS元素水平垂直居中的方法

    1.  元素水平居中 1.1  设置父元素的属性 text-align: center; 说明:此属性只针对父元素的子元素为内联元素时有效,比如:img,input,select,button等(行内 ...