简单dp题求助
  • 板块灌水区
  • 楼主ssss21
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/20 11:08
  • 上次更新2023/11/3 02:30:20
查看原帖
简单dp题求助
832659
ssss21楼主2023/8/20 11:08

题目在这里

#include<bits/stdc++.h>
using namespace std;
const int maxn=70;
int n,ans=0;
int s[5];
int dp[maxn];
int a[maxn];
/*
01
*/
int main(){
	for(int i=1;i<=4;i++){
		cin>>s[i];
	}
	for(int i=1;i<=4;i++)
{
     int c=0;
     memset(dp,0,sizeof(dp));
		memset(a,0,sizeof(a));
    for(int j=1;j<=s[i];j++){
    	cin>>a[j];
    	c+=a[j];//背包大小 
	}	
	int t=c/2;
	for(int j=1;j<=s[i];j++){//遍历物品 
//对第i个科目进行01dp 
for(int h=t;h>=a[j];h--){//遍历背包 
dp[h]=max(dp[h-a[j]]+a[j],dp[h]);//状态转移 
}
}ans+=max(c-dp[t],dp[t]);	
}
cout<<ans<<endl;
return 0;
}```
知道是01dp
写出来了,但是不知道错在哪里了,全wa
望dalao指出明路
2023/8/20 11:08
加载中...