社区讨论

十分TLE求解!!!!!!!!!

P1731[NOI1999] 生日蛋糕参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mm8x00c5
此快照首次捕获于
2026/03/02 16:26
上周
此快照最后确认于
2026/03/05 19:05
5 天前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,r[16],h[16];
int ans;
void dfs(int i,int V,int s){
	if(i>m){
		if(V==0){
			ans=min(ans,s);
		}
		return;
	}
	if(s>=ans){
		return;
	}
	for(int R=r[i-1]-1;R>=m-i+1;R--){
		for(int H=n;H>=m-i+1;H--){
			r[i]=R;
			h[i]=H;
			dfs(i+1,V-R*R*H,s+2*R*H);
		}
	}
}
int main(){
   ios::sync_with_stdio(false);
   cin.tie(0);//等价于cin.tie(false);
   cin>>n>>m;
   ans=1<<30;
   for(int R=sqrt(n);R>=m;R--){
	   	for(int H=n;H>=m;H--){
	   		r[1]=R;
	   		h[1]=H;
	   		dfs(2,n-R*R*H,2*R*H+R*R);
		}
   }
   if(ans==1<<30){
   		cout<<0;
       return 0;
   }
   cout<<ans;
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...