萌新爆零代码求调
查看原帖
萌新爆零代码求调
522847
NCO_Dongfeng_MS楼主2023/4/9 10:11

rt,自己是在想不清楚问题在哪。

#include<bits/stdc++.h>
using namespace std;
int v,c,n;
int w[10000],p[10000];
int cw,cp,best=100000;
bool flag=false;
void Do(int i){
	if(i>n){
		if(cp>=v){
			flag=true;
			if(cw<best) best=cw;
		}
		return;  
	}else{
		cw+=w[i];
		cp+=p[i];
		if(cw<=c) Do(i+1);
		cw-=w[i];
		cp-=p[i];
		Do(i+1);
	}
	return;
}
int main(){
	cin>>v>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>p[i];
	}
	Do(1);
	if(!flag) cout<<"Impossible";
	else cout<<c-best;
	return 0;
}
2023/4/9 10:11
加载中...