90 pts求助
查看原帖
90 pts求助
853792
JOE_ZengYuQiao_0928楼主2025/1/18 08:56

rt,WA on #12 #17。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2<<18;
int dp[N],n,m,t[25],w[25],V[N],W[N];
int low(int x){
	return x&(-x);
}
signed main(){
//	freopen("B.in","r",stdin);
//	freopen("B.out","w",stdout);
	cin>>m>>n;
	for(int i=1;i<=n;i++){
		cin>>t[i]>>w[i];
		W[1<<(i-1)]=t[i];
		V[1<<(i-1)]=w[i];
	}
	for(int i=1;i<(1<<n);i++){
		V[i]=V[i^low(i)]+V[low(i)];
		W[i]=max(W[i^low(i)],W[low(i)]);
	}
	memset(dp,0x3f,sizeof dp);
	dp[0]=0;
	for(int i=0;i<(1<<n);i++){
		if(W[i]<=m)
			dp[i]=V[i];
		for(int j=i;j;j=i&(j-1))
			if(V[j]<=m)
				dp[i]=min(dp[i],dp[i^j]+W[j]);
	}
	cout<<dp[(1<<n)-1];
	return 0;
} 
2025/1/18 08:56
加载中...