超级书架2(计蒜客)

 

 

 

 

 

 1 #include<iostream>
 2 using namespace std;
 3 int cow[25];
 4 int min_high = 0x3f3f3f3f;
 5 void dfs(int n,int len,int plus,int b)
 6 {
 7     if(plus>=b)
 8     {
 9        if(plus-b<min_high)
10            min_high = plus-b;
11     }
12     else
13     {
14         for(int i=n;i<=len;++i)
15         {
16             dfs(i+1,len,plus+cow[i],b);
17         }
18     }
19 }
20 int main()
21 {
22      int n,b;
23      cin>>n>>b;
24      for(int i=0; i<n;++i)
25      {
26          cin>>cow[i];
27      }
28      dfs(0,n,0,b);
29      cout<<min_high;
30      return 0;
31 } 

 

posted @ 2020-03-20 21:55  caxi  阅读(524)  评论(0编辑  收藏  举报