BZOJ大视野 2748: [HAOI2012]音量调节 解题报告

来源:互联网 发布:写网页的软件 编辑:程序博客网 时间:2024/06/05 11:13


模拟加一点剪枝



code:

/**************************************************************    Problem: 2748    Language: C++    Result: Accepted    Time:4 ms    Memory:1336 kb****************************************************************/ #include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;bool v[60][1100];int a[60],d[60];int n,result,st,maxx; void ex( int x,int k ){    if( result == maxx ) return;    if( x > n )    {           result = max( result,k );        return ;    }    if( v[x][k] ) return;    v[x][k] = true;    if( d[n] - d[x-1] + k <= result ) return;         if( k+a[x] <= maxx ) ex( x+1,k+a[x] );    if( k-a[x] >= 0 )    ex( x+1,k-a[x] );     } int main(){    int i,j;    scanf("%d",&n);    scanf("%d%d",&st,&maxx);    for( i=1;i<=n;i++ )    {        scanf("%d",&a[i]);        d[i] = d[i-1] + a[i];    }    result = -1;         ex( 1,st );         printf("%d\n",result);         return 0;}



0 0