HDOJ-1160(最长上升子序列变形)
FatMouse's Speed
HDOJ-1160
注意输出长度的时候不是输出dp[n]
#include<bits/stdc++.h>
using namespace std;
const int maxn=1003;
const int INF=0X3F3F3F3F;
int w[maxn];//weight
int s[maxn];//speed
int dp[maxn];//dp[i]表示以i结尾的最长上升子序列的长度
struct node{
int weight;
int speed;
int num;
bool operator<(const node& t)const{
if(weight<t.weight&&speed>t.speed){
return true;
}else{
return false;
}
}
};
bool cmp(const node&a,const node& b){
if(a.weight==b.weight){
return a.speed>b.speed;
}else return a.weight<b.weight;
}
node mice[maxn];
int father[maxn];
int main(){
int n=0;
int i=1;
while(cin>>w[i]>>s[i]){
mice[i]=node{w[i],s[i],i};
i++;
n++;
}
memset(dp,-INF,sizeof(dp));
sort(mice+1,mice+n+1,cmp);
memset(father,-1,sizeof(father));
for(i=1;i<=n;i++){
dp[i]=1;
for(int j=1;j<i;j++){
if(mice[j]<mice[i]){
if(dp[j]+1>dp[i]){
dp[i]=dp[j]+1;
father[i]=j;
}
}
}
}
int maxs=-INF;
int maxi=0;
for(i=1;i<=n;i++){
//cout<<dp[i]<<endl;
if(dp[i]>maxs){//没有等于
maxs=dp[i];
maxi=i;
}
}
cout<<maxs<<endl;//注意这里不是直接输出dp[n],因为dp[i]表示以i结尾的子序列的最大长度,但这可能不是最终答案的最大长度。
i=maxi;
vector<int> v;
for(;i!=-1;i=father[i]){
v.push_back(mice[i].num);
//cout<<mice[i].num<<endl;
}
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++){
cout<<v[i]<<endl;
}
//system("pause");
return 0;
}
HDOJ-1160(最长上升子序列变形)的更多相关文章
- HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- hdu1503 最长公共子序列变形
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...
- ACM: 强化训练-Beautiful People-最长递增子序列变形-DP
199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...
- HOJ Recoup Traveling Expenses(最长递减子序列变形)
A person wants to travel around some places. The welfare in his company can cover some of the airfar ...
- hdu 1080 dp(最长公共子序列变形)
题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G - G ...
- uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)
题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...
- POJ 2250(最长公共子序列 变形)
Description In a few months the European Currency Union will become a reality. However, to join the ...
- poj1836--Alignment(dp,最长上升子序列变形)
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13319 Accepted: 4282 Descri ...
- hdu1243(最长公共子序列变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1243 分析:dp[i][j]表示前i个子弹去炸前j个恐怖分子得到的最大分.其实就是最长公共子序列加每个 ...
- 洛谷 P1020 导弹拦截(dp+最长上升子序列变形)
传送门:Problem 1020 https://www.cnblogs.com/violet-acmer/p/9852294.html 讲解此题前,先谈谈何为最长上升子序列,以及求法: 一.相关概念 ...
随机推荐
- centos 7下安装配置Supervisor
1.安装Supervisor centos下安装yum install supervisor 2. systemctl enable supervisord 开机自启 systemctl start ...
- haproxy 2.2代理后端https服务
globalmaxconn 100000chroot /usr/local/haproxystats socket /var/lib/haproxy/haproxy.sock mode 600 lev ...
- C# Dictionaries
Dictionaries 字典 在C# 里是用接口 IDictionary来实现的,最常用的字典就是Dicrtionary<tkey,tvalue>,键值对的形式,和index,item ...
- python xml转excle
<?xml version="1.0" encoding="UTF-8"?> <RECORDS xmlns:xsi="http:// ...
- 联合登录 & OAuth 2.0 & OpenID
联合登录 & OAuth 2.0 & OpenID 第三方联合登录一般可以降低网站的获客成本,所以一般的网站都会做一些联合登录,常用的就是QQ.微信.微博; https://www.z ...
- Upcoming Browser Behavior Changes & Chrome & SameSite
Upcoming Browser Behavior Changes & Chrome & SameSite Chrome 80 https://auth0.com/blog/brows ...
- Flutter in DartPad
Flutter in DartPad Gist Sharing https://github.com/dart-lang/dart-pad/wiki/Sharing-Guide https://gis ...
- foreign language learning
foreign language learning free online learning websites 多邻国 https://www.duolingo.com 忆术家 https://www ...
- React & Didact
React & Didact A DIY guide to build your own React https://github.com/pomber/didact https://gith ...
- css grid layout in practice
css grid layout in practice https://caniuse.com/#search=grid subgrid https://caniuse.com/#search=cal ...