标签:str memory blog std sam ring hint body tput
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 18236 | Accepted: 6497 |
Description
Input
Output
Sample Input
100 2
Sample Output
68
Hint
Source
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; const int N=20; int n,m,ans=1e9; int mnv[N],mns[N]; void init(){ for(int i=1;i<=m;i++){ mnv[i]=mnv[i-1]+i*i*i; mns[i]=mns[i-1]+2*i*i; } } void dfs(int d,int lh,int lr,int s,int v){ if(d==0){ if(v==n&&s<ans) ans=s; return; } if(v+mnv[d]>n||s+mns[d]>ans) return; if(2*(n-v)/lr+s>ans) return; for(int tr=lr-1;tr>=d;tr--){ if(d==m) s=tr*tr; int mxh=min(lh-1,(n-mnv[d-1]-v)/(tr*tr)); for(int th=mxh;th>=d;th--){ dfs(d-1,th,tr,s+2*th*tr,v+tr*tr*th); } } } int main(){ scanf("%d%d",&n,&m); init(); dfs(m,n-mnv[m-1],sqrt(n-mnv[m-1])+1,0,0); printf("%d",ans); }
标签:str memory blog std sam ring hint body tput
原文地址:http://www.cnblogs.com/candy99/p/6057578.html