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. 超简洁代码实现CircleImageView

    效果图: 页面代码: public class CircleView extends ImageView { private Paint mPaint = new Paint(); public Ci ...

  2. Ext.tree.Panel实现单选,多选

    Extjs var productCategoryTreeLookUpFn = function(callback) { var productCategoryLookUpWindow; var pr ...

  3. bootstrap异步加载树后样式显示问题

    整个过程: 1.先加载整个页面 2.通过jquery异步请求后台返回数据 3.循环遍历数据,拼接需要的内容 4.把拼接好的数据加载到页面中. 问题: 把拼接好的内容加载到页面后,样式显示不正确.而如果 ...

  4. bazel编译tensorflow 生成libtensorflow_inference.so 和 libandroid_tensorflow_inference_java.jar

    bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//externa ...

  5. A simple problem(并查集判环)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497 题意:给定一些点和边的关系,判断S点是否 ...

  6. Appium + python - long_press定位操作实例

    from appium.webdriver.common.touch_action import TouchActionfrom appium import webdriverimport timei ...

  7. SqlMap常用参数(一)

    sqlmap可谓是利用sql注入的神器了,sqlmap的参数很多,接下介绍几种常见的参数. 一.注入access数据库常用的参数 sqlmap.py -u "url"  //判断参 ...

  8. Lua eval实现

    因为loadstring总是在全局环境中编译它的串,所以编译出的函数访问的变量是全局变量.为了避免污染全局环境我们需要用setfenv修改函数的环境 function eval(equation, v ...

  9. 【HTTP】长连接和短连接

    1. HTTP协议与TCP/IP协议的关系 HTTP的长连接和短连接本质上是TCP长连接和短连接.HTTP属于应用层协议,在传输层使用TCP协议,在网络层使用IP协议.IP协议主要解决网络路由和寻址问 ...

  10. [PHP][学习笔记][CURL]监测设备运行情况小demo

    1.curl获取的web content 不能直接echo到页面,会造成js各种错误 2.想办法处理字符串的截取.拼接 2.1.裁剪html返回的字符串 function cutStringFrom( ...