UVa11420 - Chest of Drawers(动态规划)

简介: UVa11420 - Chest of Drawers(动态规划)
#include <cstdio>#include <cstring>usingnamespacestd;
typedeflonglongLL;
constintN=70;
constintM=2;
LLmemo[N][M][N];
intn, s;
boolinput();
voidsolve();
LLdfs(intdep, intlock, intseq);
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
    }
return0;
}
boolinput()
{
scanf("%d%d", &n, &s);
if (n<0&&s<0) returnfalse;
returntrue;
}
LLdfs(intdep, intlock, intseq)
{
if (dep==n) returnseq==s;
LL&ans=memo[dep][lock][seq];
if (ans!=-1) returnans;
ans=0;
if (!lock) {
ans+=dfs(dep+1, 1, seq) +dfs(dep+1, 0, seq); 
    } else {
ans+=dfs(dep+1, 1, seq+1) +dfs(dep+1, 0, seq);
    }
returnans;
}
voidsolve()
{
memset(memo, -1, sizeof(memo));
printf("%lld\n", dfs(1, 0, 0) +dfs(1, 1, 1));
}
目录
相关文章
|
5月前
|
Java Go 图形学
一篇文章讲明白HDU4044GeoDefense(动态规划)
一篇文章讲明白HDU4044GeoDefense(动态规划)
21 0
|
6月前
动态规划——OJ题(一)
动态规划——OJ题(一)
64 1
UVa668 - Parliament(贪心)
UVa668 - Parliament(贪心)
56 0
UVa11710 - Expensive subway(最小生成树)
UVa11710 - Expensive subway(最小生成树)
41 0
HDU 4283 You Are the One(动态规划)
HDU 4283 You Are the One(动态规划)
78 0
HDU 4283 You Are the One(动态规划)
Uva 10339 - Watching Watches【数论,暴力】
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b),就可以求出多少天会相遇,然后就能求出A钟一共慢了多少秒,进而可以求出该时刻的时和分! 下面给...
1164 0
|
算法
UVa 10341 - Solve It【经典二分,单调性求解】
原题: Solve the equation:         p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0         where 0 0) 15 { 16 printf("No solut...
884 0
|
并行计算 算法 Java
HDU 1874 畅通工程续【Floyd算法实现】
畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 53806    Accepted Submission(s): 20092 Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路。
1086 0
|
人工智能
POJ 2370 Democracy in danger(简单贪心)
Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 2508 Description In one of the...
954 0