FatMouse's Speed 基础DP
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13643 Accepted Submission(s): 6011
Special Judge
believes that the fatter a mouse is, the faster it runs. To disprove
this, you want to take the data on a collection of mice and put as large
a subset of this data as possible into a sequence so that the weights
are increasing, but the speeds are decreasing.
The
data for a particular mouse will consist of a pair of integers: the
first representing its size in grams and the second representing its
speed in centimeters per second. Both integers are between 1 and 10000.
The data in each test case will contain information for at most 1000
mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
program should output a sequence of lines of data; the first line
should contain a number n; the remaining n lines should each contain a
single positive integer (each one representing a mouse). If these n
integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All
inequalities are strict: weights must be strictly increasing, and
speeds must be strictly decreasing. There may be many correct outputs
for a given input, your program only needs to find one.
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
4
5
9
7
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int maxn = ;
- struct node{
- int weight;
- int speed;
- int num;
- };
- node p[maxn];
- int dp[maxn];
- bool cmp(node A,node B){
- if(A.weight != B.weight) return A.weight<B.weight;
- else return A.speed>B.speed;
- }
- void solve(){
- int k = ,x,y;
- while(scanf("%d%d",&x,&y)!=EOF){
- p[k].weight = x;
- p[k].speed = y;
- p[k].num = k;
- k++;
- }
- sort(p+,p+k+,cmp);
- int ans = ;
- for(int i = k;i>=; i--){
- dp[i] = ;
- for(int j = i; j<=k; j++){
- if(p[j].weight>p[i].weight&&p[j].speed<p[i].speed){
- dp[i] = max(dp[i],dp[j]+);
- }
- }
- ans = max(ans,dp[i]);
- }
- printf("%d\n",ans);
- for(int i = ; i<=k; i++){
- if(dp[i] == ans){
- printf("%d\n",p[i].num);
- ans--;
- }
- if(ans == ) break;
- }
- }
- int main()
- {
- solve();
- return ;
- }
FatMouse's Speed 基础DP的更多相关文章
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- [HDOJ1160]FatMouse's Speed(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU FatMouse's Speed 基本DP
题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
随机推荐
- why TCP guarentee delivery?
Simple idea: just use a TIMEOUT, if no answer after a certain seconds, just re-deliver!
- text-size-adjust的值为100% 代替值 none
iPhone 横屏默认会放大文字,设置text-size-adjust会解决这个问题 一般用text-size-adjust:none 但建议用100%代替none text-size-adjust: ...
- 更改Xcode的缺省公司名
更改前: // testAppDelegate.m // test // // Created by gaohf on 11-5-24. // Copyright 2011 __MyCompa ...
- iOS申请真机调试证书 -- 图文详解
请参考这篇文章 : http://ios.9tech.cn/news/2013/1011/33117.html 这篇文章完全就是对的,主要是最后一步 “配置Xcode" 图没有配全,也配得不 ...
- CentOS 7 时区设置
设置时区同样, 在 CentOS 7 中, 引入了一个叫 timedatectl 的设置设置程序. 用法很简单: # timedatectl # 查看系统时间方面的各种状态 $timedatectl ...
- linux文件权限赋值
1修改权限 命令:chmod (change mode) 功能:改变文件的读写和执行权限.有符号法和八进制数字法. 选项:(1)符号法: 命令格式:chmod {u|g|o ...
- Tomcat服务器顶层结构和启动过程【转】
号外:2016 最流行的是哪一种 Java 应用服务器呢? 通过从部署的 1240 个 JVM 中得到的数据,我们能够确定出现了 862 个容器供应商,或者说是占到了运行环境的 70% 左右.这些容器 ...
- 数据库NULL和 ‘’ 区别
NULL判断时 : IS NOT NULL ''判断时: !=''
- 静默方式安装window oracle
1. setup.exe -silent -responseFile "C:\app\software\WIN64_11204\RSP\db_install_window.rsp" ...
- Greedy Change
Greedy Change time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...