标签:最小值 正整数 put 方案 制作 sum ack lan dfs
Description
Input
Output
Sample Input
100 2
Sample Output
68
Hint
Source
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<deque> #include<iomanip> #include<vector> #include<cmath> #include<map> #include<stack> #include<set> #include<fstream> #include<memory> #include<list> #include<string> using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MAXN 2147483648 #define N 33 #define MOD 1000000 #define INF 1000000009 const double eps = 1e-9; const double PI = acos(-1.0); /* 给定一个蛋糕的体积 和层数 求减去下底面后蛋糕表面积的最小值 从底层向上枚举,枚举每一层的可行H和R(加上之后小于V的) 当枚举到最后一层, 和最优解比较取值 */ int V, M, ans = 0;//体积和层数 void DFS(int level, int preh, int prer, int sumv, int sumS) { if (sumv > V)return; if (ans && sumS > ans) return; //cout << "R:: " << prer << " H:: " << preh << endl; if (level > M) { /*if (sumv == V) { cout << "SUMV " << sumv << " SUMS " << sumS << endl; }*/ if (sumv == V) { if (!ans || ans > sumS) ans = sumS; } return; } for (int r = M-level+1;r < prer; r++) { for (int h = M-level+1; h < preh; h++) { if (ans && sumS + r*2*h > ans)continue; if (sumv + (M - level + 1)*h*r*r < V ) continue; if (ans && sumS + 2 * (V - sumv) / r > ans) continue;//当前面积 加上剩余体积的最大面积 if (sumv + h*r*r <= V) DFS(level + 1, h, r, sumv + h*r*r, sumS + 2 * r*h); } } } int main() { scanf("%d%d", &V, &M); for (int r = M; r <= 100; r++) { for (int h = M; h <= 1000; h++) { if (r*r*h*M < V|| r*r*h>V) continue; DFS(2, h, r, r*r*h, r*r + 2 * r*h); } } printf("%d\n", ans); }
标签:最小值 正整数 put 方案 制作 sum ack lan dfs
原文地址:http://www.cnblogs.com/joeylee97/p/6984195.html