QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#464374#6955. AssignmentfsavcxzWA 185ms4224kbC++202.4kb2024-07-06 02:32:312024-07-06 02:32:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-06 02:32:32]
  • 评测
  • 测评结果:WA
  • 用时:185ms
  • 内存:4224kb
  • [2024-07-06 02:32:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 105;
#define pb push_back
int a[N],b[N],cost[N][N],dp[N][N][13],tp[N][13];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    //freopen("in", "r", stdin);
	int T;
	cin >> T;
	while(T--){
		int n,k;
		cin >> n >> k;
		for(int i = 1;i <= n;i++)cin >> a[i];
		for(int i = 1;i <= n;i++)cin >> b[i];

		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= n;j++){
				cin >> cost[i][j];
			}
		}
		for(int i = 0;i <= n + 1;i++){
			for(int j = 0;j <= n + 1;j++){
				for(int t = 0;t <= k;t++){
					if(i <= j)dp[i][j][t] = (int)1e9;
					tp[j][t] = (int)1e9;
				}
			}
		}
		for(int l = 1;l <= n;l++){
            if(a[l] == b[l]){
                dp[l][l][0] = 0;
            }else{
                dp[l][l][1] = 0;
                dp[l][l][0] = cost[b[l]][1];
            }
		}
		for(int l = n;l >= 1;l--){
				for(int r = 0;r <= n + 1;r++){
					for(int y = 0;y <= k;y++){
						tp[r][y] = (int)1e9;
					}
				}

			int lst = -1;
			for(int c = b[l];c <= b[l];c++){
				for(int y = 0;y <= k;y++){
					tp[l - 1][y] = 0;
				}

				for(int r = l;r <= n;r++){
					for(int y = 0;y <= k;y++){
						tp[r][y] = (int)1e9;
					}
					if(b[r] == c){
                        for(int y = 0;y <= k;y++){
                            tp[r][y] = min(tp[r - 1][y], tp[r][y]);
                        }
					}
                        for(int j = l - 1;j < r;j++){
                            for(int y = 0;y <= k;y++){
                                for(int x = 0;x + y <= k;x++){
                                    if(b[j] == c){
                                        tp[r][x + y] = min(tp[r][x + y], tp[j][x] + dp[j + 1][r][y]);
                                    }
                                }
                            }
                        }

				}
			}
			for(int r = l + 1;r <= n;r++){
					for(int x = 0;x <= k;x++){
						dp[l][r][x] = min(dp[l][r][x], tp[r][x] + cost[b[l]][r - l + 1]);
					}


				for(int i = l;i < r;++i){
					for(int x = 0;x <= k;x++){
						for(int y = 0;x + y <= k;y++){
							dp[l][r][x + y] = min(dp[l][r][x + y], dp[l][i][x] + dp[i + 1][r][y]);
						}
					}
				}
			}
		}
		cout << dp[1][n][0] << ' ';
		for(int x = 1;x <= k;x++){
			dp[1][n][x] = min(dp[1][n][x], dp[1][n][x - 1]);
			cout << dp[1][n][x] << ' ';
		}
		cout << '\n';
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 185ms
memory: 4224kb

input:

10
100 10
24 56 71 49 70 39 19 23 96 26 85 33 73 84 35 75 58 77 85 40 33 36 75 55 7 28 37 7 100 94 35 64 68 46 77 80 90 28 85 8 9 23 32 45 4 51 47 82 6 49 45 55 28 69 80 7 61 41 83 42 16 25 82 56 26 92 14 66 43 1 2 62 25 84 19 58 35 37 14 61 38 12 27 95 98 100 61 36 75 83 35 19 74 56 87 10 10 6 60 5...

output:

27473279 26539877 25650181 24801901 24025447 23252605 22479763 21733001 20960159 20221324 19493165 
30992495 30067022 29194972 28394080 27612070 26867897 26124539 25400737 24745946 24091155 23436364 
3973096 3343250 2761180 2428393 2215777 2075964 1991108 1914392 1829536 1823074 1749700 
5341649 453...

result:

wrong answer 2nd lines differ - expected: '32063854 31138381 30266331 294...4311 25690509 25035718 24380927', found: '30992495 30067022 29194972 283...737 24745946 24091155 23436364 '