QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#464362#6955. AssignmentfractalWA 443ms105852kbC++142.5kb2024-07-06 02:14:482024-07-06 02:14:49

Judging History

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

  • [2024-07-06 02:14:49]
  • 评测
  • 测评结果:WA
  • 用时:443ms
  • 内存:105852kb
  • [2024-07-06 02:14:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n, a[121], b[121], k;
int dp[121][121][121][31];
int C[121][121], f[121][121][31];

void solve() {
	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 >> C[i][j];
		}
	}	
	const int inf = 1e9 + 100;
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
			for (int x = 0; x <= n; ++x) {
				for (int l = 0; l <= k; ++l) {
					f[i][j][l] = inf;
					dp[i][j][x][l] = inf;
				}
			}			
		}
	}
	for (int i = 1; i <= n; ++i) {		
		for (int x = 1; x <= n; ++x) {
			dp[i][i][x][x != b[i]] = 0;
			f[i][i][x != b[i]] = min(f[i][i][x != b[i]], C[x][1]);
		}
		for (int x = 1; x <= n; ++x) {
            for (int l = 0; l <= k; ++l) {
                dp[i][i][x][l] = min(dp[i][i][x][l], f[i][i][l]);
            }
        }
		dp[i][i][0][a[i] != b[i]] = 0;
		f[i][i][a[i] != b[i]] = 0;
	}
	for (int len = 2; len <= n; ++len) {
		for (int l = 1, r = len; r <= n; ++l, ++r) {
			for (int x = 1; x <= n; ++x) {				
				for (int j = 0; j <= k; ++j) {
                    int jj;
					jj = j + (x!=b[l]);
					if (jj <= k) dp[l][r][x][jj] = min(dp[l][r][x][jj], f[l + 1][r][j]);
					jj = j + (x!=b[r]);
					if (jj <= k) dp[l][r][x][jj] = min(dp[l][r][x][jj], f[l][r - 1][j]);
					jj = j + (x!=b[l]) + (l!= r && x != b[r]);
					if (jj <= k) dp[l][r][x][jj] = min(dp[l][r][x][jj], min(dp[l + 1][r - 1][x][j], f[l + 1][r - 1][j]));
				}				
				for (int j = 0; j <= k; ++j) {
					f[l][r][j] = min(f[l][r][j], C[x][len] + dp[l][r][x][j]);
				}
			}
			for (int x = 1; x <= n; ++x) {				
				for (int j = 0; j <= k; ++j) {
                    dp[l][r][x][j] = min(dp[l][r][x][j], f[l][r][j]);
                }
            }
			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][0][x + y] = min(dp[l][r][0][x + y], f[l][i][x] + f[i + 1][r][y]);
						f[l][r][x + y] = min(f[l][r][x + y], dp[l][r][0][x + y]);
					}
				}
			}
		}
	}
	//~ n = 3;
	//~ cout << dp[2][4][2][0] << '\n';
	//~ cout << f[1][4][0] << '\n';
	int ans = f[1][n][0];
	cout << ans << " ";
	for (int i = 1; i <= k; ++i) {
		ans = min(ans, f[1][n][i]);
		cout << ans << " \n"[i == k];
	}
		
}


int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	cin >> t;
	while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 443ms
memory: 105852kb

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 21736708 20997873 20269714 19580515
32114104 31188631 30316581 29515689 28733679 27989506 27246148 26522346 25867555 25210419 24555628
5088208 4331688 3701842 3264509 2931722 2791909 2707053 2630337 2485590 2152803 2012990
7304585 634020...

result:

wrong answer 1st lines differ - expected: '27473279 26539877 25650181 248...3001 20960159 20221324 19493165', found: '27473279 26539877 25650181 248...6708 20997873 20269714 19580515'