zoukankan      html  css  js  c++  java
  • CF 463D Gargari and Permutations [dp]

    给出一个长为n的数列的k个排列(1 ≤ n ≤ 1000; 2 ≤ k ≤ 5)。求这个k个数列的最长公共子序列的长度

    dp[i]=max{dp[j]+1,where j<i 且j,i相应的字符在k个排列中都保持同样的相对位置}

    #include <iostream>
    #include <vector>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    using namespace std;
    #define pb push_back
    const int NN=2222;
    int f[7][NN];
    int maxn;
    int anti[7][NN];
    int dp[NN];
    int main(){
    #ifndef ONLINE_JUDGE
    	freopen("/home/rainto96/in.txt","r",stdin);
    #endif
    	int n,k;cin>>n>>k;
    	for(int i=1;i<=k;i++)
    		for(int j=1;j<=n;j++){
    			cin>>f[i][j];
    			anti[i][f[i][j]]=j;
    		}
    	for(int i=1;i<=n;i++){
    		for(int j=0;j<i;j++){
    			bool flag=false;
    			for(int m=1;m<=k;m++)
    				if(anti[m][f[1][i]]<anti[m][f[1][j]])
    					flag=true;
    			if(flag) continue;
    			dp[i]=max(dp[i],dp[j]+1);
    		}
    		maxn=max(maxn,dp[i]);
    	}
    	cout<<maxn<<endl;
    	return 0;
    }


  • 相关阅读:
    Python 字符串
    python 元组用法
    python 字典用法
    环境配置
    桥式整流以及电容作用
    三角序列的正交性
    MDS
    ISOMAP
    randperm
    数据库~Mysql里的Explain说明
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/6705884.html
Copyright © 2011-2022 走看看