NC216041. GPA
描述
输入描述
The first line contains one single integer .
Then lines follow. The i-th line contains 2 integers .
The input guarantees that ,.
输出描述
Output the minimum number of the days that Alice will be sad.
示例1
输入:
4 1 2 2 3 1 2 1 1
输出:
1
C++(clang++11) 解法, 执行用时: 52ms, 内存消耗: 63484K, 提交时间: 2020-12-26 20:55:51
#include<bits/stdc++.h> using namespace std; int INF=0x3f3f3f3f; int n; int a[4010],b[4010]; int f[4010][4010];//f[i][j]表示截止到第i天,j次不开心次数的当前值 int main() { cin>>n; memset(f,INF,sizeof(f)); f[0][0]=0; for(int i=1;i<=n;i++) { cin>>a[i]>>b[i]; } for(int i=1;i<=n;i++) { for(int j=0;j<i;j++) { int p; p= f[i-1][j]>(i-1)*a[i]; f[i][j+p]=min(f[i][j+p],f[i-1][j]+a[i]); p= f[i-1][j]>(i-1)*b[i]; f[i][j+p]=min(f[i][j+p],f[i-1][j]+b[i]); } } for(int i=0;i<n;i++) { if(f[n][i]<INF) { cout<<i; return 0; } } return 0; }