【CodeForces】463D Gargari and Permutations DP
来源:互联网 发布:如何领淘宝内部优惠券 编辑:程序博客网 时间:2024/05/24 02:07
传送门:【CodeForces】463D Gargari and Permutations
题目分析:对于所有的数对(x,y)如果x在所有的串中都排在y的前面,则建边(x,y),最后跑一遍最长路,最长路的长度就是答案。
代码如下:
#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>using namespace std ;#define REP( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )#define FOR( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )#define REV( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )#define travel( e , H , u ) for ( Edge* e = H[u] ; e ; e = e -> next )#define CLR( a , x ) memset ( a , x , sizeof a )typedef long long LL ;const int MAXN = 1005 ;const int MAXE = 1000005 ;struct Edge {int v ;Edge* next ;} E[MAXE] , *H[MAXN] , *cur ;int G[MAXN][MAXN] ;int d[MAXN] ;int in[MAXN] ;int Q[MAXN] , head , tail ;int n , k ;int s[MAXN] ;void clear () {cur = E ;CLR ( H , 0 ) ;CLR ( G , 0 ) ;CLR ( d , 0 ) ;CLR ( in , 0 ) ;head = tail = 0 ;}void addedge ( int u , int v ) {cur -> v = v ;cur -> next = H[u] ;H[u] = cur ++ ;}void topo () {FOR ( i , 1 , MAXN ) if ( !in[i] ) d[i] = 1 , Q[tail ++] = i ;while ( head != tail ) {int u = Q[head ++] ;travel ( e , H , u ) {int v = e -> v ;if ( d[v] < d[u] + 1 ) d[v] = d[u] + 1 ;if ( -- in[v] == 0 ) Q[tail ++] = v ;}}}void solve () {int ans = 0 ;clear () ;FOR ( _ , 1 , k ) {FOR ( i , 1 , n ) {scanf ( "%d" , &s[i] ) ;REP ( j , 1 , i ) ++ G[s[j]][s[i]] ;}}FOR ( i , 1 , n ) FOR ( j , 1 , n ) if ( G[i][j] == k ) addedge ( i , j ) , ++ in[j] ;topo () ;FOR ( i , 1 , n ) if ( d[i] > ans ) ans = d[i] ;printf ( "%d\n" , ans ) ;}int main () {while ( ~scanf ( "%d%d" , &n , &k ) ) solve () ;return 0 ;}
0 0
- 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)
- CF 463D Gargari and Permutations (dp)
- CF 463D Gargari and Permutations [dp]
- 【CODEFORCES】 D. Gargari and Permutations
- Codeforces 463D. Gargari and Permutations (dp,distinct下的LCS问题)
- 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
- Codeforces 264 (Div. 2) D. Gargari and Permutations
- Oracle的统计分析方法
- [C/C++]_[初级]_[使用C字符串(或者std::string)处理函数获取文件所在目录
- WebView中JS与Java安全地相互调用
- Android Button的使用方法
- iOS 汉字转拼音
- 【CodeForces】463D Gargari and Permutations DP
- NSString的几种常用方法
- Ajax实践之匿名函数判断用户是否存在
- 随机化算法——舍伍德算法的应用
- linux系统移植到tiny6410(简易过程)
- Ubuntu下修改DNS重启也能用的方法
- eclipse配置ndk
- iOS 拨打电话 拨打完以后会回到原来的应用
- 黑马程序员_(高新技术二)