80分dfs开O2超时
查看原帖
80分dfs开O2超时
677234
FstAutoMaton楼主2022/9/21 18:16

不会dp

#include <iostream>
using namespace std;
int a[15];
bool l[1005];
int x[10] = {0, 1, 2, 3, 5, 10, 20}, cnt;
void dfs( int step, int sum )
{
    if( step > 6 )
    {
        if( !l[sum] && sum )
        {
            cnt ++;
        }
        l[sum] = 1;
        return ;
    }
    for( int i = 1; i <= a[step]; i ++ )
    {
        dfs( step + 1, sum + x[step] * i );
    }
    dfs( step + 1, sum );
}
int main()
{
    for( int i = 1; i <= 6; i ++ ) scanf( "%d", &a[i] );
    dfs( 1, 0 );
    cout << "Total=" << cnt;
}
2022/9/21 18:16
加载中...