This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
int n, t, s;
int dp[20005][55], val[20005], pre[20005][55];
string ss[55];
int best[55];
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> t >> s;
for(int i = 1; i <= t; i ++){
cin >> val[i];
val[i] += val[i - 1];
}
for(int i = 1; i <= n; i ++){
cin >> ss[i];
for(int j = 0; j < t; j ++){
if(ss[i][j] == '1') pre[j + 1][i] = pre[j][i];
else pre[j + 1][i] = j + 1;
}
}
for(int i = 1; i <= t; i ++){
pre[i][0] = i;
sort(pre[i], pre[i] + n + 1);
}
for(int i = 0; i < 20005; i ++)
for(int j = 0; j < 55; j ++)
dp[i][j] = inf;
dp[0][0] = 0;
for(int i = 1; i <= s; i ++){
for(int j = 0; j <= n; j ++)
best[j] = inf;
for(int j = 1; j <= t; j ++){
for(int k = 0; k <= n; k ++){
for(int l = pre[j - 1][k]; l < pre[j][k]; l ++)
best[k] = min(best[k], dp[l][i - 1] - val[l] * k);
dp[j][i] = min(dp[j][i], best[k] + val[j] * k);
}
}
cout << dp[t][i] << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |