HDU1160FatMouse's Speed
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
const int maxn=;
struct point
{
int w,s,per,id;
}p[maxn];
int cmp(point a,point b)
{
return a.s>b.s;
}
int dp[maxn];
int main()
{
int i,j,k,n,m;
n=;
memset(dp,,sizeof(dp));
while(scanf("%d%d",&p[n].w,&p[n].s)!=EOF)
{
p[n].id=n;
p[n].per=;
n++;
}
sort(p+,p+n,cmp);
int max;
dp[]=;//dp[i]记录以第i个元素结尾的最长递增的长度
for(i=;i<n;i++)
{
max=;
for(j=;j<i;j++)
{
if(p[j].w<p[i].w && p[j].s>p[i].s)
{
if(dp[j]>=max)
{
max=dp[j];
p[i].per=j;//记录i位置的前驱
}
}
dp[i]=max+;
}
}
max=-0x3f3f3f3f;
int end;
for(i=;i<n;i++)
{
if(max<=dp[i])
{
max=dp[i];
end=i;
}
}
printf("%d\n",max);
stack<int> ok;
while(end!=)
{
ok.push(end);
end=p[end].per;
}
while(!ok.empty())
{
printf("%d\n",p[ok.top()].id);
ok.pop();
}
return ;
} /*二分写法*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct X{
int s,w,sb;
};
bool cmp(X a,X b)
{
return (a.s>b.s)||(a.s==b.s&&a.w>b.w);//这里排序注意了,由于本题数据水的不能再水,a.w<b.w也过了,正解应该是a.w>b.w
}
X xx[];
int pre[];
int fnm[];
int shuchu[];
int main()
{
int i=,n=,w,s;
while(scanf("%d%d",&w,&s)!=EOF)
{
xx[n].w=w;
xx[n].s=s;
xx[n].sb=n++;
}
n--;
sort(xx+,xx+n+,cmp);/*
for(i=1;i<=n;i++)
printf("%d %d\n",xx[i].w,xx[i].s);*/
int lsb=,j,l,r;
fnm[]=;
pre[fnm[]]=-;
for(i=;i<=n;i++)
{
l=,r=lsb;
while (l<=r) //二分查找
{
int mid = (l+r)>>;
if (xx[fnm[mid]].w < xx[i].w)
l=mid+;
else
r=mid-;
}
j=l;
if(j>lsb)
lsb++;
fnm[j]=i;//存下标,相当于c[j]=a[i];
if(j!=)//fnm小标从0开始,所以要判断第一个
pre[i]=fnm[j-];//j-1的元素肯定是最长递增中的元素
else
pre[i]=-;
}
printf("%d\n",lsb+);
int xsb=fnm[lsb];
i=;
while(pre[xsb]!=-)
{
shuchu[i++]=xx[xsb].sb;
xsb=pre[xsb];
}
printf("%d\n",xx[xsb].sb);
for(i=lsb-;i>=;i--)
printf("%d\n",shuchu[i]);
return ;
}
HDU1160FatMouse's Speed的更多相关文章
- HDU-1160-FatMouse's Speed(线性DP,LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 动态规划:HDU1160-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(DP, 最长递增子序列)
链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- LYDSY模拟赛day2 Dash Speed
/* 弃坑 */ #include<cstdio> #include<algorithm> using namespace std; ,M=N*; ],nxt[N<< ...
- FatMouse's Speed——J
J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- OpenVZ VPS加速方案–Final Speed
body,td { font-family: 微软雅黑; font-size: 10pt } OpenVZ VPS加速方案–Final Speed OpenVZ VPS加速方案–Final Spe ...
- UNITY3D单词学习 speed和velocity的区别
在日常用语中,这两个词没有区别,可以通用. 而在物理学里,velocity 是一个矢量(vector quantity)表示起点与终点间直线距离的长度除以所用时间所得的量,并注明方向;而 speed ...
- HD1160FatMouse's Speed(最长单调递增子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 首个vue.js项目收尾中……
前言: 4.26号入手vue.js+elementUI,迄今为止我们的工作应该可以暂时告一段落了:下周开始,又是新的“征程”. 过程:站在接近完成的角度来看这个项目,似乎的确有许多事情需要自己阐述. ...
- console.log篇
前言: 从接触变成开始,就用到了神奇的“console.log”,原来其中还有很多不为自己知道的“小秘密”,今天就深入研究一下吧 1.可以F12打开控制台,输入console.log(xxx),就可以 ...
- 《C++ Primer Plus》第14章 C++中的代码重用 学习笔记
C++提供了集中重用代码的手段.第13章介绍的共有继承能够建立is-a关系,这样派生类可以重用基类的代码.私有继承和保护继承也使得能够重用基类的代码,单建立的是has-a关系.使用私有继承时,积累的公 ...
- PHP中str_replace和substr_replace有什么区别?
两个函数的定义:(1)str_replace() 函数替换字符串中的一些字符(区分大小写). 该函数必须遵循下列规则: 如果搜索的字符串是一个数组,那么它将返回一个数组. 如果搜索的字符串是一个数组, ...
- MUI ajax数据请求(list)
服务器返回格式 { "code": "1001", "message": "查询成功", "data" ...
- ubuntu 关闭显示器的命令
sleep 2s ; gnome-screensaver-command -a或sleep 2s ; xset dpms force off2秒后关闭显示器
- Module 'null' not found异常解决办法
百度原因:是因为在 /WEB_INF/web.xml文件中 <servlet> <servlet-name>ActionServlet</servlet-name ...
- 安装Memcache的PHP扩展
查看memcached是否启动 # ps -ef | grep memcached 安装Memcache的PHP扩展 1.在http://pecl.php.net/package/memcache 选 ...
- 【BZOJ2588】Spoj 10628. Count on a tree 主席树+LCA
[BZOJ2588]Spoj 10628. Count on a tree Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lasta ...
- Windows Phone 页面切换动画
1.首先引用Microsoft.Phone.Toolkit 2.将App.xaml.cs 中的 RootFrame = new PhoneApplicationFrame(); 改成RootFrame ...