动态规划:HDU1160-FatMouse's Speed(记录动态规划状态转移过程)
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5546 Accepted Submission(s): 2393
Special Judge
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.
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<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
struct mice
{
int w,s;
int pos;
} m[maxn]; struct Dp
{
int num[maxn];
int Num;
} dp[maxn];
bool cmp(mice a,mice b)
{
return a.w<b.w;
}
int main()
{
int t = 1;
int W,S;
while(scanf("%d%d",&W,&S) != EOF)//处理这个题输入的的办法
{
m[t].w = W;
m[t].s = S;
m[t].pos = t;
t++;
} /*
可以输入0 0结束看看自己的输入是否正确
while(scanf("%d%d",&W,&S) && W)//处理这个题输入的的办法
{
m[t].w = W;
m[t].s = S;
m[t].pos = t;
t++;
}
t--;
for(int i=1;i<=t;i++)
printf("%d %d\n",m[i].w,m[i].s); */ t--;//用来记录有多少个元素
int Max = 0;//记录最长的递减子序列
sort(m,m+t,cmp);//拍一下序,cmp函数自己写一下
for(int i=1;i<=t;i++)
{
dp[i].Num = 1;
dp[i].num[1] = m[i].pos;
}
for(int i=1; i<=t; i++)
{
for(int j=0; j<=i; j++)
{
if(m[j].s > m[i].s && m[j].w < m[i].w)
{
if(dp[j].Num+1 > dp[i].Num)//如果符合状态的转移要求
{
for(int k=1;k<=dp[j].Num;k++)//记录状态的数组一起跟着转移
{
dp[i].num[k] = dp[j].num[k];
dp[i].num[k+1] = m[i].pos;//当前状态也要放入
}
dp[i].Num = dp[j].Num + 1;
if(dp[i].Num > Max)
Max = dp[i].Num;
}
}
}
} bool flag = false;
printf("%d\n",Max);
for(int i=1;i<=t;i++)
{
if(dp[i].Num == Max)
{
flag = true;
for(int j=1;j<=dp[i].Num;j++)
{
if(dp[i].num[j]!=0)
printf("%d\n",dp[i].num[j]);
}
break;
}
}
return 0;
}
动态规划:HDU1160-FatMouse's Speed(记录动态规划状态转移过程)的更多相关文章
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU1160 FatMouse's Speed —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...
- HDU1160:FatMouse's Speed(最长上升子序列,不错的题)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1160 学的东西还是不深入啊,明明会最长上升子序列,可是还是没有A出这题,反而做的一点思路没有,题意就不多说 ...
- [HDU1160]FatMouse's Speed
题目大意:读入一些数(每行读入$w[i],s[i]$为一组数),要求找到一个最长的序列,使得符合$w[m[1]] < w[m[2]] < ... < w[m[n]]$且$s[m[1] ...
- 读懂TCP状态转移
读懂TCP状态转移过程,对理解网络编程颇有帮助,本文将对TCP状态转移过程进行介绍,但各状态(总共11个)含义不在本文介绍的范围,请参考文末的书目列表. TCP状态转换图(state transiti ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- hdoj1160 FatMouse's Speed 动态规划
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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(LIS+记录路径)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 7天学完Java基础之0/7
笔记-7天学完Java基础之0/7 1.常用命令提示符(cmd) 启动:Win+R,输入cmd
- 提升Java代码质量(三)
Item7:覆盖equals时需要遵守通用约定 在我们日常开发过程中,重写equals是比较常用的,但存在许多不合适的覆盖方式导致错误,最好的避免方法就是不去重写equals.但有时我们的业务又需要建 ...
- Vue2.0搭建脚手架(vue-cli)
一.安装node.js 进入官网下载node.js 二.安装 cnpm 1.说明:npm(node package manager)是nodejs的包管理器,用于node插件管理(包括安装.卸载.管理 ...
- [Unity3D] 如何识别屏幕边缘
出现的问题 Unity3D中长度单位是米 使用Screen.resolutions获取的屏幕信息单位是像素 也就是说,即使获取了屏幕相关信息及参数,也无法把信息转换成可在editor中使用的信息.当时 ...
- unhandled event loop exception解决方案
今天突然遇到这个问题,打开ADT就报unhandled event loop exception, 原因是ATI显卡的HydraDM.exe HydraDM64.exe进程somehow跟ADT起了冲 ...
- 【extjs6学习笔记】0.3 准备: 类库结构2
- redis在Windows下以后台服务一键搭建集群(单机--伪集群)
redis在Windows下以后台服务一键搭建集群(单机--伪集群) 一.概述 此教程介绍如何在windows系统中同一台机器上布置redis伪集群,同时要以后台服务的模式运行.布置以脚本的形式,一键 ...
- Mysql数据库学习总结(一)
数据库概念 数据库(Database)是按照数据结构来组织.存储和管理数据,建立在计算机存储设备上的仓库. 简单说,数据库就是存放数据的仓库.和图书馆存放书籍.粮仓存放粮食类似. 数据库分类 分为 关 ...
- Metasploitable渗透测试实战——Windows漏洞 MS08-067复现
Ms08-067 攻防环境: 攻击机:kali ip:198.168.12.212 靶机:Window XP 未打过ms08-067补丁 ip:198.168.12.209
- 关于前端的交互 ajax
对于交互来说,可以利用原生的javascript和jquery 这篇说的就是jquery 1 不是跨域的 利用$ajax({})这个函数实现的 $.ajax({ url: "", ...