Skip to content

Instantly share code, notes, and snippets.

@yanring
Last active April 6, 2019 02:05
Show Gist options
  • Save yanring/c2b28c215dbac3160479bbc86870d52b to your computer and use it in GitHub Desktop.
Save yanring/c2b28c215dbac3160479bbc86870d52b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,res=9999999;
double max_d=0;
double d[52];
int p[52];
void dfs(int index, double sum_d, int sum_gold){
if(sum_d>=max_d){
res = min(res,sum_gold);
return;
}else{
if(sum_d<d[index]){
// 一定要贿赂当前的怪
dfs(index+1, sum_d+d[index], sum_gold+p[index]);
}else{
//可贿赂可不贿赂
dfs(index+1, sum_d+d[index], sum_gold+p[index]);
dfs(index+1, sum_d, sum_gold);
}
}
}
int main()
{
cin>>n;
for(int i = 1; i <= n; i++){
cin>>d[i];
if(d[i]>max_d)
max_d = d[i];
}
for(int i = 1; i <= n; i++){
cin>>p[i];
}
dfs(1,0,0);
cout<<res<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment