40分求助

P4799 [CEOI2015 Day2] 世界冰球锦标赛

Konnyaku_q @ 2023-05-16 17:21:13

老师讲了100分做法,但没懂,故发此贴

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
long long e,n,m,a[1000],ans=0;
void dfs(long long idx,long double s)
{
    if(s>m)
    {
        return;
    }
    if(idx>n)
    {
        ans++;
        return;
    }
    dfs(idx+1,s);
    dfs(idx+1,s+a[idx]) ;
 }  
int main()
{

 cin>>n>>m;
 for(int i=1;i<=n;i++)
 {
    cin>>a[i];
 }
 dfs(1,0);
 cout<<ans<<endl;

}

by _wzcxx @ 2023-05-16 17:29:54

折半搜索OK?


by Hughpig @ 2023-05-16 17:30:19

@wzbxx 大哥这正解双向搜索你直接dfs肯定不对啊


|