1 条题解

  • 1
    @ 2023-9-24 15:07:54
    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1010;
    int a[N], dp[N][N];
    int main(){
    	freopen("card.in","r",stdin);
    	freopen("card.out","w",stdout);
    	int n, m;
    	cin >> n;
    	for (int i = 1; i <= n; i ++) cin >> a[i];
    	cin >> m;
    	if(m < 5){
    		cout << m << endl;
    		return 0;
    	}
    	int t = m;
    	m -= 5;
    	sort(a+1, a+1+n);
    	for (int i = 1; i < n; i++){
    		for(int j = 0;j <= m; j ++){
    			if(j >= a[i]){
    				dp[i][j] = max(dp[i-1][j],dp[i-1][j-a[i]]+a[i]);
    			}else{
    				dp[i][j] = dp[i-1][j];
    			}
    		}
    	}
    	cout << t - a[n] - dp[n-1][m] << endl;
    	return 0;
    } 
    
    • 1

    信息

    ID
    504
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    173
    已通过
    23
    上传者