hdoj1160 FatMouse's Speed 动态规划
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7213 Accepted Submission(s): 3181
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.
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct node //老鼠的属性
{
int w; //体重
int s; //速度
int x; //输入时的顺序号
}mice[];
int cmp(node a,node b) //以体重为标准,将老鼠按体重递减排序
{
return a.w<b.w;
}
int main()
{
int n=;
int i,j;
int much[],head[]; //分别记录第i只老鼠为止,子序列长度与前驱存储位置(mice数组中下标)
while(scanf("%d %d",&mice[n].w,&mice[n].s)!=EOF)
mice[n].x=n+,n++;
sort(mice,mice+n+,cmp); //排序
head[]=-; //终止标记
much[]=;
int max1=,x; //由第一只老鼠到当前检索位置为止,子序列的最大长度和其前驱位置在前驱记录数组head中的下标
for(i=;i<=n;i++)
{
head[i]=-;
much[i]=;
for(j=;j<i;j++)
{
if(mice[i].w>mice[j].w && mice[i].s<mice[j].s && much[j]+>much[i]) //体重严格递增,速度严格递减,子序列更长
{
much[i]=much[j]+;
head[i]=j;
if(much[i]>max1) //前驱处理
{
max1=much[i];
x=i; }
//cout<<"i="<<i<<"j="<<j<<endl;
} }
}
//cout<<"X==="<<x<<endl;
int road[];
i=;
while() //处理路劲记录
{
//cout<<"X="<<mice [x].x<<endl;
road[i++]=mice[x].x;
//cout<<x<<" "<<head[x]<<endl;
x=head[x];
if(x==-)
break;
}
printf("%d\n",max1);
for(i--;i>=;i--)
printf("%d\n",road[i]);
return ;
}
hdoj1160 FatMouse's Speed 动态规划的更多相关文章
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- [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 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- FatMouse's Speed——J
J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- FatMouse's Speed(HDU LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- IDEA开发web程序配置Tomcat
1.下载zip版的Tomcat 7,并解压2.在IDEA中配置Tomcat 7 在idea中的Settings(Ctrl+Alt+s)(或者点击图标 ) 弹出窗口左上过滤栏中输入“Applicatio ...
- vue diff算法 patch
1.diff比较算法 图示: diff比较只会在同层级进行, 不会跨层级比较. 所以diff是:广度优先算法. 时间复杂度:O(n) 代码示例: <!-- 之前 --> <div&g ...
- C++ union使用注意
union在我们敲代码的时候的使用概率远远小于struct.所以我们常常不太关心她.就知道他是使用内存复用技术.同一个时刻,他仅仅能存在一个成员的值. C中,我们在union中能够包括struct的, ...
- “error: command 'x86_64-linux-gnu-gcc' failed with exit status 1” in virtualenv
Most of the time these are dependency-issues. Following the stack-trace of the gcc compiler one ca ...
- windows installer服务无法启动,无法打开任何msi文件
如果不成功就在"依存关系"中找是否有其他的文件没有启用. 启用"remote procedure call(rpc)" 启用"workstation& ...
- 重要:VC DLL编程
VC DLL编程 静态链接:每个应用程序使用函数库,必须拥有一份库的备份.多个应用程序运行时,内存中就有多份函数库代码的备份. 动态连接库:多个应用程序可以共享一份函数库的备份. DLL的调用方式:即 ...
- 用户研究Q&A(1)
近来,不少同事开始认同用户研究的价值,希望通过接触,理解和研究用户来获取提升产品的有效信息.这绝对是件好事,因为我一直抱持的理念是,研究并不是藏在实验室或者握在少部分人手中的稀罕货,更重要是一种理念和 ...
- PHP-手册阅读笔记
1.第一次遇到$_ENV为空数组的情况, 原来是PHP.INI中variables_order为'GPCS'(表示系统在定义PHP预定义变量时的顺序是GET,POST,COOKIES,SERVER,只 ...
- PHP-PHP.INI常用配置详解
variables_order: 假如为'GPCS'表示系统在定义PHP预定义变量时的顺序是GET,POST,COOKIES,SERVER, 此时$_ENV为空数组, 只要把'E'添加到'GPCS'后 ...
- Linux-Linux下安装redis报错"undefined reference to__sync_add_and_fetch_4"解决办法
如果出现这种错误可以在make的时候加上CFLAGS="-march=i686" 即 make CFLAGS="-march=i686" ----------- ...