90分谜题
查看原帖
90分谜题
79073
ILXC__SL楼主2019/5/22 12:50

求助, WA\color{red}{\text{WA}} 了 第二个点

#include<bits/stdc++.h>
using namespace std;
int n,m,ans=0x7ffff;
int maxs[20],maxv[20];

int read()
{
    int x=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while( isdigit(c)){x=x*10+c-'0';  c=getchar();}
    return x*f;
}

inline void init()
{
    ios::sync_with_stdio(false);
    return;
}

void readdata()
{
    n=read();
    m=read();
    for(register int i=1;i<=20;i++)
    {
        maxs[i]=maxs[i-1]+2*i*i;
        maxv[i]=maxv[i-1]+i*i*i;
    }
    return;
}

void DFS(int o,int r,int h,int v,int s,int num)
{
    if(o>m)
    {
        if(v==0) ans=min(s,ans);
        return;
    }
    if(s+maxs[num]>ans) return;
    if(v-maxv[num]<0  ) return;
    long long Maxv=(long long)r*r*h*num; if(v>Maxv*100) return;
    
    for(register int i=r-1;i>=num;i--)
    {
       if(o==1) s=i*i;
       for(register int l=h-1;l>=num;l--)
       DFS(o+1,i,l,v-i*i*l,s+2*i*l,num-1);
    }
}

void work()
{
    DFS(1,sqrt(n),n-1,n,0,m);
    if(ans==0x7ffff) printf("0\n");else printf("%d\n",ans);
    return;
}

int main()
{
    init();
    readdata();
    work(); 
    return 0;
}
/*
输入:
16385 13
输出:
2599
我的输出:
0
*/ 
2019/5/22 12:50
加载中...