CF 463D Gargari and Permutations (dp)
来源:互联网 发布:铝材下料软件 编辑:程序博客网 时间:2024/06/06 13:57
要找到所有序列中的最长的公共子序列,定义状态dp[i]为在第一个序列中前i个数字中的最长公共子序列的长度,状态转移方程为dp[i]=max(dp[i],dp[j]+1); j<i
还要先预处理出两个数在所有序列中的位置关系,例如两个数a和b,只要在任意一个序列中a在b的后面,则记after[a][b]=1。
在递推的时候如果!after[a][b],则进行状态转移。
具体细节看代码。
#include<cstdio>#include<algorithm>#include<cstring>#include<cstdlib>#define M(a,b) memset(a,b,sizeof(a))#define ll long long#define rep(i,a,b) for(i=a;i<=b;i++)using namespace std;bool after[1005][1005];//after[a][b]=1表示a在b的后面int a[10][1005],dp[1005];int main(){ int n,k,i,j,l; scanf("%d%d",&n,&k); rep(i,1,k) rep(j,1,n) scanf("%d",&a[i][j]); rep(i,1,k) rep(j,1,n) rep(l,1,j) after[a[i][j]][a[i][l]]=1; int ans=-1; rep(i,1,n) { dp[i]=1; int tmp=a[1][i]; rep(j,1,i-1) if(!after[a[1][j]][tmp]) dp[i]=max(dp[i],dp[j]+1); ans=max(dp[i],ans); } printf("%d\n",ans); return 0;}
0 0
- CF 463D Gargari and Permutations (dp)
- CF 463D Gargari and Permutations [dp]
- Codeforces 463D. Gargari and Permutations【DP】
- 【CodeForces】463D Gargari and Permutations DP
- codeforces 463D D. Gargari and Permutations(dp)
- Codeforces 463D Gargari and Permutations DP(LCS变形)
- Codeforces 463D Gargari and Permutations(BFS)
- codeforces 463D Gargari and Permutations
- Codeforces 463D Gargari and Permutations
- Codeforces 463D Gargari and Permutations(BFS)
- 【CODEFORCES】 D. Gargari and Permutations
- Codeforces 463D. Gargari and Permutations (dp,distinct下的LCS问题)
- Codeforces 463D Gargari and Permutations【思维建图+Floyd跑最长路】不愧是CF的评测姬
- Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题
- Codeforces #264 (Div. 2) D. Gargari and Permutations
- Codeforces #264 (Div. 2) D. Gargari and Permutations
- Codeforces #264 div.2 D. Gargari and Permutations
- Codeforces #264(div 2)D.Gargari and Permutations
- Cocos2d-x学习笔记(十三)CCLabel详解
- Linux 内核开发 - 内核定时器
- 《Effective C++》学习笔记(七)
- priority_queue相关操作
- hibernate对象关系映射(基于注解)
- CF 463D Gargari and Permutations (dp)
- STL之vector,数组线性容器array,list容器,算法find,find_if,bind1st,仿函数
- Spring AOP 完成日志记录
- 成功 我 需要 你
- JavaScript--事件对象
- 使用ajax gson增强用户体验
- 第一个项目(八)碰撞检测
- MyBatis 2章 MyBatis与Spring整合
- set的相关操作