#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int T = 20002;
const int N = 51;
const int S = 51;
const int INF = 2e9 + 10;
int n, t, s, p[T], dp[S][T], last[T][N], minVal[N];
string a[N];
void ReadInput(){
cin >> n >> t >> s;
for(int i = 1; i <= t; i++)
cin >> p[i];
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] = '*' + a[i];
}
}
void Solve(){
for(int i = 1; i <= t; i++)
p[i] += p[i - 1];
for(int i = 1; i <= t; i++)
for(int j = 1; j <= n; j++)
last[i][j] = (a[j][i] == '0'? i : last[i - 1][j]);
for(int i = 1; i <= t; i++){
last[i][0] = 0;
sort(last[i], last[i] + 1 + n);
}
for(int i = 0; i <= s; i++)
for(int j = 0; j <= t; j++)
dp[i][j] = INF;
dp[0][0] = 0;
for(int i = 1; i <= s; i++){
for(int j = 0; j <= n; j++)
minVal[j] = dp[i - 1][0];
for(int j = 1; j <= t; j++){
int sum = 0;
for(int k = 1; k <= n; k++)
if (a[k][j] == '1')
sum += p[j];
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + sum);
for(int k = 0; k <= n; k++){
for(int l = last[j - 1][k]; l < last[j][k]; l++)
minVal[k] = min(minVal[k], dp[i - 1][l] - p[l] * k);
dp[i][j] = min(dp[i][j], minVal[k] + p[j] * k);
}
}
}
for(int i = 1; i <= s; i++)
cout << dp[i][t] << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ReadInput();
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |