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个

 #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = ;
struct stone{
int a,b;
bool operator<(const stone &rhs)const{
return b < rhs.b;
}
}s[maxn];
int dp[maxn][maxn];
int main(){
int n;
while(scanf("%d",&n),n){
memset(dp,-INF,sizeof dp);
dp[][] = ;
for(int i = ; i <= n; ++i){
dp[][i] = ;
scanf("%d%d",&s[i].a,&s[i].b);
}
sort(s+,s+n+);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
dp[i][j] = max(dp[i-][j],dp[i-][j+] + s[i].a - s[i].b*j);
printf("%d\n",dp[n][]);
}
return ;
}

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. 菜鸟nginx源代码剖析数据结构篇(六) 哈希表 ngx_hash_t(上)

    菜鸟nginx源代码剖析数据结构篇(六) 哈希表 ngx_hash_t(上) Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog. ...

  2. 用 JSQMessagesViewController 创建一个 iOS 聊天 App - 第 2 部分

    原文链接 : Create an iOS Chat App using JSQMessagesViewController – Part 2 原文作者 : Mariusz Wisniewski 译者 ...

  3. B1024 生日快乐 递归。。。

    bzoj1024叫生日快乐,其实很简单,但是没看出来就很尴尬... Description windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕.现在包括win ...

  4. 关于逆元&&lucas定理

    lucas是求组合数C(m,n)%p,有一个公式:C(m,n) = C(m/p,n/p)*C(m%p,n%p). (a*b)%c==a%c*b%c,但是(a/b)%c!=a%c/b%c,所以我们要算b ...

  5. element快速开发建站的动态UI------优

    网站快速成型工具 只为这样的你:  Element,一套为开发者.设计师和产品经理准备的基于 Vue 2.0 的组件库,提供了配套设计资源,帮助你的网站快速成型 http://element.elem ...

  6. EmguCV学习——视频与图片互转

    其实视频转图片在上篇文章中已经有些眉目了,其实就是按帧读取视频,然后把帧保存就ok.然后自己再加个进度条美化一下...这代码简单易懂,还是直接上代码吧. 视频转图片 /// <summary&g ...

  7. mysql数据库知识点总结

    一.数据库的基本操作 --------------------------------------------------------------数据库的安装以后更新----------------- ...

  8. python特性小记(一)

    一.关于构造函数和析构函数 1.python中有构造函数和析构函数,和其他语言是一样的.如果子类需要用到父类的构造函数,则需要在子类的构造函数中显式的调用,且如果子类有自己的构造函数,必然不会自动调用 ...

  9. 九九乘法表(for循环)

    九九乘法表:<br /><script>for(var i=0;i<10;i++){ for(var j=1;j<=i;j++) { var a=j*i docum ...

  10. Embedded之Makefile

    1 Header files The header files are empty, so you can create them with touch: $ touch a.h $ touch b. ...