导弹拦截&&http://acm.nyist.net/JudgeOnline/problem.php?pid=79
来源:互联网 发布:macbook pro 2017 知乎 编辑:程序博客网 时间:2024/06/05 05:10
动态规划感觉挺有意思的,以前不怎么爱,,现在有点改观了。。。。(*^__^*) 嘻嘻……,做这一类体,主要是找准状态转移方程。。。。
这一题的状态转移方程。。
从后往前:
if(a[i]>a[j]) dp[i]=max(dp[i],dp[j]+1);
从前往后:
if(a[i]<a[j]) dp[i]=max(dp[i],dp[j]+1);
AC代码:
#include<iostream>#include<algorithm>using namespace std;int dp[20],a[20];int main(){ int Case; cin>>Case; while(Case--) { int n; cin>>n; dp[n]=1; for(int i=0;i<n;++i) { dp[i]=1; cin>>a[i]; } int maxx=-0xfffff; for(int i=n-1;i>0;--i) { for(int j=i+1;j<=n;++j) if(a[i-1]>a[j-1]) dp[i]=max(dp[i],dp[j]+1); maxx=max(dp[i],maxx); } cout<<maxx<<endl; }return 0;}
法二:
#include<iostream>#include<algorithm>using namespace std;int dp[20],a[20];int main(){ int Case; cin>>Case; while(Case--) { int n; cin>>n; for(int i=0;i<n;++i) cin>>a[i]; int maxx=-0xfffff; for(int i=1;i<=n;++i) { dp[i]=1; for(int j=1;j<i;++j) if(a[i-1]<a[j-1]) dp[i]=max(dp[i],dp[j]+1); maxx=max(dp[i],maxx); } cout<<maxx<<endl; }return 0;}
法三:
#include<iostream>#include<algorithm>using namespace std;bool cmp(int a, int b){return a>b;}int main(){int n; cin>>n; while(n--) { int a[21]; int b[21]; int m; cin>>m; for(int i=0;i<m;++i) cin>>a[i]; int p=0; for(int i=0;i<m;++i){ int* c=lower_bound(b,b+p,a[i],cmp); if(c-b==p) ++p; *c=a[i];}cout<<p<<endl; }return 0;}
- 导弹拦截&&http://acm.nyist.net/JudgeOnline/problem.php?pid=79
- http://acm.nyist.net/JudgeOnline/problem.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=434
- http://acm.nyist.net/JudgeOnline/problem.php?pid=13
- http://acm.nyist.net/JudgeOnline/problem.php?pid=239
- http://acm.nyist.net/JudgeOnline/problem.php?pid=129
- http://acm.nyist.net/JudgeOnline/problem.php?pid=431
- http://acm.nyist.net/JudgeOnline/problem.php?pid=301
- http://acm.nyist.net/JudgeOnline/problem.php?pid=451
- http://acm.nyist.net/JudgeOnline/problem.php?pid=459
- http://acm.nyist.net/JudgeOnline/problem.php?pid=20
- http://acm.nyist.net/JudgeOnline/problem.php?pid=267
- http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- http://acm.nyist.net/JudgeOnline/problem.php?pid=309
- http://acm.nyist.net/JudgeOnline/problem.php?pid=325
- http://acm.nyist.net/JudgeOnline/problem.php?pid=420
- http://acm.nyist.net/JudgeOnline/problem.php?pid=488
- http://acm.nyist.net/JudgeOnline/problem.php?pid=150
- 在C#中使用SQL存储过程说明
- Java 操作CSV 文件
- apt命令的一些参数...
- 不借助辅助空间,直接逆序单链表
- 超详细的2440中断机制分析!
- 导弹拦截&&http://acm.nyist.net/JudgeOnline/problem.php?pid=79
- Linux内核结构
- 剪刀、石头、布游戏
- wifi 自动化测试脚本
- Struts-初级篇-开发注意问题及小技巧
- ChartDirector 5.0 for python 笔记【6】Circular Label Layout
- android边缓存边播放mp4
- 自学数据分析需要的bat
- 编译器对extern的处理