FatMouse's Speed HDU - 1160 最长上升序列, 线性DP
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int w, s;
int index; //储存标号
} mouse[]; //小鼠的信息
//先体重,后速度
bool cmp(node a,node b)
{
if(a.w==b.w)
return a.s<b.s;
return a.w<b.w;
}
int main()
{
int dp[],load[],ans[];
int i, maxl,maxi,n,temp,x;
i=;
while(scanf("%d%d",&mouse[i].w,&mouse[i].s)!= EOF)
{
mouse[i].index=i;
dp[i]=;
load[i]=;
i++;
}
sort(mouse+,mouse+i,cmp);
//总数量
n=i-;
maxl=;
for(int i=;i<=n;i++)
{
for(int j=;j<i;j++)
if(mouse[i].w>mouse[j].w&&mouse[i].s<mouse[j].s&&dp[i]<dp[j]+)
{
//如果i的体重比j的小,而且速度j的大,并且还得j的最长子序列加一要大于目前i的最长子序列
dp[i] = dp[j] + ;
load[i] = j;
}
if(dp[i]>maxl)
{
//最长序列
maxl = dp[i];
//序列最后一个
maxi = i;
}
}
temp=maxi;
x=;
//将最终的结果标号存入数组中
while(temp!=)
{
ans[x]=temp;
temp=load[temp];
x++;
}
printf("%d\n", maxl);
for(int i=maxl-;i>= ;i--)//标号存的时候是倒序,所以要给它反过来
printf("%d\n",mouse[ans[i]].index);
return ;
}
FatMouse's Speed HDU - 1160 最长上升序列, 线性DP的更多相关文章
- (最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160
http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...
- XHXJ's LIS HDU - 4352 最长递增序列&数位dp
代码+题解: 1 //题意: 2 //输出在区间[li,ri]中有多少个数是满足这个要求的:这个数的最长递增序列长度等于k 3 //注意是最长序列,可不是子串.子序列是不用紧挨着的 4 // 5 // ...
- ZOJ 1108 FatMouse's Speed (HDU 1160) DP
传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...
- hdu 1087 最长上升序列和 dp
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- (LIS)最长上升序列(DP+二分优化)
求一个数列的最长上升序列 动态规划法:O(n^2) //DP int LIS(int a[], int n) { int DP[n]; int Cnt=-1; memset(DP, 0, sizeof ...
- HDU 1069 Monkey and Banana(线性DP)
Description A group of researchers are designing an experiment to test the IQ of a monkey. They wi ...
- HDU - 1160 最长上升子序列以及记录路径
题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...
- poj2279 Mr. Young's Picture Permutations[勾长公式 or 线性DP]
若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数 ...
- Common Subsequence POJ - 1458 最长公共子序列 线性DP
#include <iostream> #include <algorithm> #include <string> #include <cstring> ...
随机推荐
- android手机遍历安装应用
/** * 遍历程序列表,判断是否安装安全支付服务 * * @return */ public boolean isMobile_spExist() { PackageManager manager ...
- String实例 (练习)
练习题1:用户输入一段字符串,要求统计出在该段字符串中,数字,字母以及其他字符各出现过几次??? 代码实现: 运行结果: 补充:1. 连接符的使用: +用作连接符时,只能连接字符串,即“ ”双 ...
- PAT-1005 Spell It Right 解答(C/C++/Java/python)
1.Description: Given a non-negative integer N, your task is to compute the sum of all the digits of ...
- Android.mk文件LOCAL_SDK_VERSION选项
Api分类 internal api 翻译为内部API,理解为供sdk内部使用的API. 这类接口最初打算就是不对外公开的,有点private的意思. hide api 在源码中看到使用@hide 标 ...
- Android中点击按钮获取string.xml中内容并弹窗提示
场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...
- 关于mac下redis的安装和部署
近来学习scrap分布式,需要用到redis,但以前没接触过,所以记录一下自己的安装过程. 准备:Mac,redis-5.0.4.tar.gz 1.压缩包到官网下(建议下载稳定版)网址:redis.i ...
- opencv —— findContours、drawContours 寻找并绘制轮廓
轮廓图像与 Canny 图像的区别 一个轮廓一般对应一系列的点,也就是图像中的一条曲线.轮廓图像和 Canny 图像乍看起来表现几乎是一致的,但其实组成两者的数据结构差别很大: Canny 边缘图像是 ...
- 使用PropTypes进行类型检查
原文地址 1.组件特殊属性——propTypes 对Component设置propTypes属性,可以为Component的props属性进行类型检查. import PropTypes from ' ...
- java读取中文文本文件乱码问题
今天遇到的问题是这样:用java读取一个中文文本文件,但读取到的却是乱码,之前一直没有问题,查清楚后,原来是因为今天是用的windows的记事本来编辑的文件,因编码方式是的不同而导致了乱码,解决方法就 ...
- Mybaits(9)MyBatis级联-2
一.鉴别器和一对多级联 1.完善体检表,分为男雇员体检和女雇员体检表 (1)持久层dao编写 package com.xhbjava.dao; import com.xhbjava.domain.Ma ...