UVA 1638(动态规划)
来源:互联网 发布:歼十外销知乎 编辑:程序博客网 时间:2024/05/19 19:43
有高为1到n的杆子各一根排成一行,从左往右能看见l根,从右往左能看见r根,问可能的方案数。
dp[i][j][k]表示i根高度不同的杆子从左往右能看见j根,从右往左能看见k根,根据高度最低的那根杆子分类。
#include <stdio.h>#include <string.h>#include <cmath>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 30 + 6;ll f[maxn][maxn][maxn];/*f[i][l][r]表示i根棍子从左边能看见l根从右边能看见r根*//*转移为f[i][l][r] = f[i-1][l-1][r] + f[i-1][l][r-1] + (i-2)*f[i-1][l][r]*/const int mod = 10056;ll dfs(int tot,int l,int r){ ll & res = f[tot][l][r]; if(res != -1)return res; if(tot==1&&l==r&&r==1)return res = 1; else if(tot==1)return res = 0; res = dfs(tot-1,l-1,r) + dfs(tot-1,l,r-1) + (tot-2)*dfs(tot-1,l,r); return res;}int main(int argc, char const *argv[]){ int T; scanf("%d",&T); memset(f,-1,sizeof f); for(int cas = 1,n; cas <= T; ++cas) { int a,b; scanf("%d%d%d",&n,&a,&b); printf("%lld\n", dfs(n,a,b)); } return 0;}
0 1
- UVA 1638(动态规划)
- UVA 1638- Pole Arrangement(动态规划)
- 动态规划,递推(杆子的排列,uva 1638)
- uva 674 - Coin Change(动态规划)
- UVA 111 - History Grading(动态规划)
- UVA - 674 - Coin Change(动态规划)
- UVA - 10003 - Cutting Sticks(动态规划)
- UVA - 116 - Unidirectional TSP(动态规划)
- UVA - 10192 - Vacation (动态规划, LCS)
- UVA - 147 - Dollars(动态规划)
- 【UVA】1626-Brackets sequence(动态规划)
- 【UVA】12186-Another Crisis(动态规划)
- 【UVA】1218 - Perfect Service(动态规划)
- uva 10192 Vacation(动态规划:LCS)
- UVA - 147 - Dollars (动态规划)
- UVA - 624 - CD (动态规划)
- UVa 1347 - Tour(动态规划)
- UVA - 103 - Stacking Boxes (动态规划)
- 基于Energia的MPS430单片机编程
- hdu 4632区间dp
- 关于Windows 数据库服务器更换为Linux 数据库服务器的前提条件
- 硅谷归来:中国在“互联网夹",美国已进入“新硬件时代”
- Hadoop MapReduce
- UVA 1638(动态规划)
- Ie中的404错误
- Redis源码阅读之aof.c
- 【c语言】关于+1的各种情况
- HDU4706——Children's Day(简单模拟)
- 细说UI线程和Windows消息队列
- 位逆置变换
- 获取字符串中每个字母出现的次数
- Implement Trie (Prefix Tree)