#include <bits/stdc++.h>
using namespace std;
const int mx_N = 50 + 3;
const int mx_S = 50 + 3;
const int mx_T = 2e4 + 3;
int n, t, s;
long long dp[mx_S][mx_T];
long long p[mx_T], a[mx_T][mx_N], b[mx_N];
string r[mx_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t >> s;
for(int i = 0; i < t; ++i){
cin >> p[i + 1];
p[i + 1] += p[i];
}
for(int i = 0; i < n; ++i)
cin >> r[i];
for(int i = 0; i < t; ++i)
for(int j = 0; j < n; ++j)
a[i + 1][j] = (r[j][i] & 1) ? a[i][j] : i + 1;
for(int i = 1; i <= t; ++i){
a[i][n] = i;
sort(a[i], a[i] + n + 1);
}
for(int i = 1; i <= n; ++i)
dp[0][i] = INT_MAX;
dp[0][0] = 0;
for(int i = 1; i <= s; ++i){
for(int k = 0; k <= n; ++k)
b[k] = INT_MAX;
for(int j = 1; j <= t; ++j){
dp[i][j] = INT_MAX;
for(int k = 0; k <= n; ++k){
for(int l = a[j - 1][k]; l < a[j][k]; ++l)
b[k] = min(dp[i - 1][l] - p[l] * k, b[k]);
dp[i][j] = min(b[k] + p[j] * k, dp[i][j]);
}
//cout << dp[i][j] << " dp[" << i << "][" << j << "]\n";
}
dp[i][0] = INT_MAX;
cout << dp[i][t] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
2432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |