poj1190 生日蛋糕
来源:互联网 发布:视频直播间php源码 编辑:程序博客网 时间:2024/04/28 04:58
点击打开链接
题意看链接,因为是汉语版的题目。
思路:据说dfs,还是基础的经典dfs。可叹,自己还是不怎么会啊………………
#include<iostream>#include<stdio.h>#include<memory.h>#include<math.h>using namespace std;#define inf 10000000int n,m,s;void dfs(int num,int leftV,int r,int h,int ls){ if(num<=m&&leftV<=0)return ;//层数不够,无剩余体积结束 if(num==m+1&&leftV!=0)return ;//层数到了,但是体积不够或者还有剩余也返回 if(num==m+1&&leftV==0)//当正好符合的时候,比较找一个最小的 { if(ls<s) s=ls; return ; } if((m-num+1)*(r-1)*(r-1)*(h-1)<leftV) return ; //剩余的层数体积最大值和小于剩余体积,结束。(剪枝) for(int rr=r-1; rr>m-num; rr--)//半径最小的时候不会小于层数的个数(每层的半径为1) { for(int hh=m-num+1; hh<h; hh++)//每层最小为1的时候,所以第一次不能小于层数 { if(num==1) { if(rr*rr+2*rr*hh>s) break; dfs(num+1,leftV-rr*rr*hh,rr,hh,ls+rr*rr+2*rr*hh); } else { if(2 * rr * hh + ls >= s || leftV-rr*rr*hh < 0) break; dfs(num+1, leftV-rr*rr*hh, rr, hh, ls+2*rr*hh); } } }}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { s=inf; int minR=sqrt(double(n)); dfs(1,n,minR,n,0); cout<<s<<endl; } return 0;}
- poj1190 生日蛋糕
- poj1190生日蛋糕
- poj1190生日蛋糕
- poj1190 生日蛋糕
- POJ1190-生日蛋糕
- POJ1190生日蛋糕
- poj1190 生日蛋糕
- poj1190 生日蛋糕 dfs
- poj1190 生日蛋糕 搜索+剪枝
- poj1190深搜 生日蛋糕
- POJ1190生日蛋糕题解
- POJ1190 生日蛋糕(DFS)
- Poj1190 生日蛋糕 DFS
- poj1190 生日蛋糕 -dfs
- poj1190 生日蛋糕 dfs
- poj1190——生日蛋糕
- poj1190 生日蛋糕 (搜索剪枝)
- poj1190生日蛋糕(dfs+剪枝)
- POJ 4046
- 算法连载6
- Javascript 之 Ext.Button 初级
- UML图 符号的含义
- C++ fstream 的易错的用法
- poj1190 生日蛋糕
- 项目整体管理
- 使用AlertDialog类创建对话框
- android xml文件解析
- UINavigationController 不要随便autorelease
- poll()例程(包含 bind,listen,accept,setsockopt 的用法)
- POJ 2456(二分哲学)
- git下载android framework源码
- 获取当前执行程序的路径,并用资源管理器打开日志文件夹