UVA 111 History Grading
来源:互联网 发布:嵌入式跟单片机 编辑:程序博客网 时间:2024/06/06 20:09
DP,题意晦涩难懂。LCS问题。
源序列要经过转换。 比如 4 2 1 3. 是指 事件1 发生在第四,事件2 发生在第二,事件3发生在第一 ,事件4发生在 第三。
转换后的序列为 : 3 2 4 1 。
所以说很丧病。UVA很多题都是一大堆题意。
我用的二维数组。其实可以优化 滚动或者一维。
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<vector>#include<cmath>#define INF 0x7fffffff#define eps 1e-8#define LL long long#define PI 3.141592654#define CLR(a,b) memset(a,b,sizeof(a))#define FOR(i,a,n) for(int i= a;i< n ;i++)#define FOR0(i,a,b) for(int i=a;i>=b;i--)#define pb push_back#define mp make_pair#define ft first#define sd second#define sf scanf#define pf printf#define acfun std::ios::sync_with_stdio(false)#define SIZE 1000+1using namespace std;int a[SIZE];int b[SIZE];int dp[SIZE][SIZE];int main(){ int n; sf("%d",&n); int tmp; FOR(i,0,n) { sf("%d",&tmp); a[tmp-1]=i; } while(sf("%d",&tmp)!=EOF) { b[tmp-1]=0; FOR(i,1,n) { sf("%d",&tmp); b[tmp-1]=i; } CLR(dp,0); FOR(i,0,n) FOR(j,0,n) { if(a[i]==b[j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]); } pf("%d\n",dp[n][n]); }}
0 0
- UVa 111 - History Grading
- uva 111 History Grading
- [UVA 111] History Grading
- uva:111 - History Grading
- UVa 111 - History Grading
- UVa 111 - History Grading
- UVA 111 History Grading
- UVa 111 - History Grading
- Uva - 111 - History Grading
- UVa 111 - History Grading
- UVa 111 - History Grading
- Uva-111-History Grading
- UVa 111: History Grading
- UVA - 111 History Grading
- UVA 111 History Grading
- uva 111History Grading
- UVA 111 History Grading
- UVA-111 History Grading
- CY-TIY物联网实验箱基础实验功能参数简介
- xcode6命令行打包ipa
- 应届生应聘软件开发岗位推荐书籍
- 申请苹果开发者账号We are unable to process your request的问题
- UIView To Image
- UVA 111 History Grading
- Android用户程序安装的位置及preferences.xml的位置
- Android Volley完全解析(二),使用Volley加载网络图片
- VC++6错误检查工具
- R中的各种假设检验
- GDB中应该知道的几个调试方法
- percona-xtrabackup yum安装
- Python gevent vs thread vs sequence
- 查找最小的k个元素 【微软面试100题 第五题】