摘要: 题意:两个数列,第一行的数字可以和第二行的数字连线。连线有如下条件,被连上的两数字必须相等,且每个数字只能连一条线,每条连线必须与且仅与另一条连线相交,相交两连线上的数字不能相等。问最多能连多少条线。分析:dp。f[i][j]表示第一行的前i个数字和第二行的前j个数字最多能连几条线,则f[i][j]=max(f[i-1][j],f[i][j-1],f[k-1][l-1]+2)。k是第一行前i-1个数字中最右一个能与第二行j位置连线的数的位置。l同理。这样状态转移为n,状态为n^2,总的时间复杂度为n^3。但是我们可以不用每次顺序查找k,l的值,我们进行预处理。数组last_equal1[i][ 阅读全文
posted @ 2013-03-15 14:48 undefined2024 阅读(434) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;int main(){ //freopen("t.txt", "r", stdin); int t; scanf("%d", &t); while (t--) { int x, y; scanf("%d%d", &x, &y); if ( 阅读全文
posted @ 2013-03-15 13:27 undefined2024 阅读(137) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxl 60int n;char st[maxl];bool have_bed[maxl];bool occured[maxl];int hash(char ch){ return ch - 'A';}int work(){ int len = strlen(st); int ans = 0; for (i 阅读全文
posted @ 2013-03-15 13:10 undefined2024 阅读(175) 评论(0) 推荐(0)