【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
2017-05-18 00:13
471 查看
显然将扩张按从大到小排序之后,只有不超过前34个有效。
d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少。
然后用二重循环更新即可,
d[i][j*A[i]]=max(d[i][j*A[i]],d[i-1][j]);
d[i][j]=max(d[i][j],d[i-1][j]*A[i]);
当某次更新时,检验其符合了答案的条件,就输出。
显然可以用滚动数组优化到空间为线性。
注意爆int的问题。
此外,瞎几把搜+花式剪枝也能过。
d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少。
然后用二重循环更新即可,
d[i][j*A[i]]=max(d[i][j*A[i]],d[i-1][j]);
d[i][j]=max(d[i][j],d[i-1][j]*A[i]);
当某次更新时,检验其符合了答案的条件,就输出。
显然可以用滚动数组优化到空间为线性。
注意爆int的问题。
此外,瞎几把搜+花式剪枝也能过。
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; bool cmp(const int &a,const int &b){ return a>b; } bool check(int hh,int ww,int aa,int bb){ return ((hh>=aa && ww>=bb) || (hh>=bb && ww>=aa)); } int d[36][100010],a,b,h,w,n,A[100010]; int main(){ // freopen("d.in","r",stdin); scanf("%d%d%d%d%d",&a,&b,&h,&w,&n); if(check(h,w,a,b)){ puts("0"); return 0; } for(int i=1;i<=n;++i){ scanf("%d",&A[i]); } sort(A+1,A+n+1,cmp); d[0][h]=w; for(int i=1;i<=n && i<=34;++i){ for(int j=1;j<=100000;++j){ d[i][min((ll)j*(ll)A[i],100000ll)]=max(d[i][min((ll)j*(ll)A[i],100000ll)],d[i-1][j]); if(check(min((ll)j*(ll)A[i],100000ll),d[i][min((ll)j*(ll)A[i],100000ll)],a,b)){ printf("%d\n",i); return 0; } d[i][j]=max((ll)d[i][j],min((ll)d[i-1][j]*(ll)A[i],100000ll)); if(check(j,d[i][j],a,b)){ printf("%d\n",i); return 0; } } } puts("-1"); return 0; }
相关文章推荐
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains(树状数组)
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) B
- 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) B. T-shirt buying
- [Updating] Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 解题报告
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)A题
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B. T-shirt buying(想法题)
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B. T-shirt buying(想法题)
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) A题
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
- CodeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)C题C. Fountains
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) A. Carrot Cakes
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains 乱搞
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) E. Cards Sorting 树状数组
- 【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal
- 【树状数组】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) C. DNA Evolution
- 01背包问题(当有的背包重量是非整数时)的递归(优化成动态规划+再用滚动数组优化)解法+一些动态规划(递归,搜索)的高级技巧
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组