Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1190怎么剪枝。。。。。。。。。。。。。。

Posted by yuhailin at 2009-05-22 17:06:27
各位大哥,仁兄:帮忙看一下1190,怎么剪枝都超时............
#include <iostream>
using namespace std;
#define in(a,b) (a<b?a:b)
int n,m;
int minv[21],mins[21];
int best = 65535;

void solution(int v,int s,int floor,int r,int h)
{
    if(floor==0)
    {
        if(v==n && s<best)
            best=s;
        return ;
    }
    if(v+minv[floor-1]>n || s+mins[floor-1]>best || 2*(n-v)/r+s>best)
        return ;
    int i,j,hh;
    for(i=r-1;i>=floor;i--)
    {
        if(floor==m)
            s=i*i;
        hh=in((n-v)/(i*i),h-1);
        for(j=hh;j>=floor;j--)
            solution(v+i*i*j,s+2*i*j,floor-1,i,j);
    }

}

int main()
{
    int i;
    minv[0]=0;
    mins[0]=1;
    for(i=1;i<=20;i++)
    {
        minv[i]=minv[i-1]+i*i*i;
        mins[i]=mins[i-1]+2*i*i;
    }
    cin>>n;
    cin>>m;

    solution(0,0,m,n+1,n+1);
    if(best==65535)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<best<<endl;
    }
    return 0;
}
不知道该怎么剪了。。。。。。。。。。。。。。。



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator