【DP】 cf 590D Top Secret Task

来源:互联网 发布:腾讯视频for mac官方 编辑:程序博客网 时间:2024/05/17 02:15
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 155;const int INF = 0x3f3f3f3f;int dp[maxn][maxn * maxn];void update(int &x, int y){if(x > y) x = y;}void work(){int n, K, s;scanf("%d%d%d", &n, &K, &s);memset(dp, INF, sizeof dp);dp[0][0] = 0;for(int i = 1; i <= n; i++) {int x;scanf("%d", &x);for(int j = i-1; j >= 0; j--) {for(int k = 0; k <= i * j; k++) {if(dp[j][k] == INF) continue;update(dp[j+1][k+i-j-1], dp[j][k]+x);}}}int ans = INF;for(int i = 0; i <= min(s, n * n); i++) {ans = min(ans, dp[K][i]);}printf("%d\n", ans);}int main(){//freopen("data", "r", stdin);work();return 0;}

0 0
原创粉丝点击