Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大牛帮忙看看啊!!!能找到的数据都测试了,输出都是正确的,但是提交就wrong,求大牛帮忙看看,感激不尽 错误代码如下: #include <iostream> using namespace std; #define MAX(a, b) a>b?a:b #define N 202 int color[N], len[N], after[N]; int dp[N][N][N]; int main() { int cas, m, n; int i, j, l, r, k, p, id; int seq[N], cnt; bool vis[N]; cas = 1; scanf("%d", &m); while(m--) { scanf("%d", &n); scanf("%d", &seq[1]); id = cnt = 1; for(i = 2; i <= n; i++){ scanf("%d", &seq[i]); if(seq[i] == seq[i-1]) cnt++; else { color[id] = seq[i-1]; len[id++] = cnt; cnt = 1; } } color[id] = seq[n]; len[id++] = cnt; memset(vis, false, sizeof(vis)); memset(after, -1, sizeof(after)); for(i = 1; i < id-2; i++){ //after[i] 的值为下一段与第i段颜色相同的下标 if(vis[i]) continue; int tmp = i; for(j = i+2; j < id; j++) if(color[tmp] == color[j]){ after[tmp] = j; tmp = j++; vis[j] = true; } } memset(dp, 0, sizeof(dp)); for(j = 1; j < id; j++){ //遍历长度 for(l = 1; l+j-1 < id; l++){ r = l+j-1; for(i = after[r], k = 0;; i = after[i]){ if(j == 1) dp[l][r][k] = (len[r]+k)*(len[r]+k); else { dp[l][r][k] = dp[l][r-1][0]+(len[r]+k)*(len[r]+k); for(p = r-2; p >= l; p--) if(color[p] == color[r]) dp[l][r][k] = MAX(dp[l][r][k], dp[l][p][k+len[r]]+dp[p+1][r-1][0]); } if(i == -1) break; else k += len[i]; } } } printf("Case %d: %d\n", cas++, dp[1][id-1][0]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator