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));
}
目录
相关文章
|
8月前
|
容器
POJ 3640 Conformity
POJ 3640 Conformity
40 0
|
6月前
poj 3298 数状数组
题目大意是一条大街上住着n个乒乓球爱好者,他们的水平高低用一个数值表示,他们经常举办比赛,比赛要三个人,一人当裁判。对裁判是有一定要求的,裁判的水平必须介于两选手之间且必须住他们中间,计算可以举办多少场比赛
23 0
POJ 1936 All in All
POJ 1936 All in All
63 0
poj 3620
题意:给出一个矩阵,其中有些格子干燥、有些潮湿。       如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大       的湖泊,求最大的湖泊。       也就是求出最大的连在一块儿的潮湿的格子的数目。
553 0
|
人工智能
POJ 2531
初学dfs参考别人代码,如有雷同,见怪不怪。#include using namespace std; int aa[25][25]; int maxa=0; int step[25]={0},n; void dfs(int a,int b) { int t=b; step...
676 0
|
人工智能 BI
|
JavaScript
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1035 0
|
机器学习/深度学习 算法

热门文章

最新文章