제출 #341722

#제출 시각아이디문제언어결과실행 시간메모리
341722phathnv조교 (CEOI16_popeala)C++11
100 / 100
291 ms10732 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int T = 20001;
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] = i;
        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] = INF;
        for(int j = 1; j <= t; j++)
            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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...