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 ;
}

最新文章

  1. ActiveXObject函数详解
  2. TListView Header重绘和高度设置
  3. Aptana studio 3前端开发编辑器推荐
  4. matlab figure 论文级别绘图
  5. min—width的使用
  6. SHA-1加密
  7. if exists用法
  8. UIStepper UISlider UISwitch UITextField 基本控件
  9. appledoc:Objective-C注释文档生成工具
  10. Derby的下载安装和使用,(和JAVA中使用Derby)
  11. Lintcode249 Count of Smaller Number before itself solution 题解
  12. gitlab搭建和使用
  13. Ajax跨越问题原因分析与解决思路
  14. LeetCode - Cut Off Trees for Golf Event
  15. 在Django中运行脚本文件以及打印出SQL语句。
  16. tomcat生成调试日志配置
  17. LeetCode Anagrams My solution
  18. 3ds Max 中的导航控件ViewCube入门介绍
  19. Netty高性能编程备忘录(下)
  20. Hyperledger Fabic中的Transaction流程

热门文章

  1. Struts 配置文件
  2. A Round Peg in a Ground Hole(圆与凸包)
  3. Your configuration specifies to merge with the ref &#39;refs/heads/v.autoCheckProduct.20190325&#39; from the remote, but no such ref was fetched.
  4. python2.X现在不能安装Django了:Collecting django Using cached Django-2.0.tar.gz
  5. doctype声明 过渡transitional 严格strict 框架frameset
  6. webapi时间字段返回格式设置及返回model首字母小写
  7. VMWare linux安装mysql 5.7.13
  8. 复习java基础第三天(集合:Collection、Set、HashSet、LinkedHashSet、TreeSet)
  9. 2、scala条件控制与循环
  10. (转)基于Metronic的Bootstrap开发框架经验总结(9)--实现Web页面内容的打印预览和保存操作