POJ 2279
线性DP
本题的正解是杨氏矩阵与钩子定理
但是这道题用DP的思想非常好

但是这样会MLE...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
unsigned int dp[31][31][31][31][31], n, num[6];
int main() {
while(1) {
cin >> n;
if(!n) break;
memset(num, 0, sizeof(num));
memset(dp, 0, sizeof(dp));
dp[0][0][0][0][0] = 1;
for(int i = 1; i <= n; i++) cin >> num[i];
for(int i = 0;i <= num[1]; i++) {
for(int j = 0; j <= num[2] && j <= i; j++) {
for(int k = 0; k <= num[3] && k <= j; k++) {
for(int l = 0; l <= num[4] && l <= k; l++) {
for(int m = 0; m <= num[5] && m <= l; m++) {
if(i + 1 <= num[1]) dp[i + 1][j][k][l][m] += dp[i][j][k][l][m];
if(j + 1 <= num[2] && j + 1 <= i) dp[i][j + 1][k][l][m] += dp[i][j][k][l][m];
if(k + 1 <= num[3] && k + 1 <= j) dp[i][j][k + 1][l][m] += dp[i][j][k][l][m];
if(l + 1 <= num[4] && l + 1 <= k) dp[i][j][k][l + 1][m] += dp[i][j][k][l][m];
if(m + 1 <= num[5] && m + 1 <= l) dp[i][j][k][l][m + 1] += dp[i][j][k][l][m];
}
}
}
}
}
cout << dp[num[1]][num[2]][num[3]][num[4]][num[5]] << endl;
}
return 0;
}
POJ 2279的更多相关文章
- 轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- [POJ 2279] Mr. Young's Picture Permutations
[题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...
- 【杨氏矩阵+勾长公式】POJ 2279 Mr. Young's Picture Permutations
Description Mr. Young wishes to take a picture of his class. The students will stand in rows with ea ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
随机推荐
- spark 的RDD各种转换和动作
今天先把spark的各种基本转换和动作总结下,以后有时间把各种用法放上去. 1 RDD基本转换操作 map.flagMap.distinct coalesce.repartition coale ...
- Open Cascade:AIS_InteractiveContext如何调用函数选择AIS对象
AIS_InteractiveContext如何调用函数选择AIS对象 myAISContext->MoveTo(point.x, point.y, myView); myAISContext- ...
- Python协程函数
1 协程函数 1.1 协程函数理解 协程函数就是使用了yield表达式形式的生成器 def eater(name): print("%s eat food" %name) whil ...
- python-DB模块
基于python的接口测试框架设计 连接数据库 首先是连接数据库的操作,最好是单独写在一个模块里, 然后便于方便的调用,基于把connection连接放在__init__()方法里 然后分别定义D ...
- RestTemplate进行表单请求,注意要使用MultiValueMap
在对接API的时候,有时候文档中会说,表单提交,这时候就需要用到 MultiValueMap来操作,下面给大家展示一个简单的demo. MultiValueMap<Object, Object& ...
- Mycat主从分离
1. mycat原理 主从的读写是不同的,主能写能读,再从上写是无法同步到主的,因此需要中间件将主从的读写进行分离,使得主从各司其职,相当于负载均衡的作用.中间件可以是proxy或者mycat.客户端 ...
- 【php】 自带的过滤机制
<?php print_r(filter_list()); ?> 输出类似: Array ( [0] => int [1] => boolean [2] => float ...
- python--管道, 事件, 信号量, 进程池
一 . 管道 (了解) from multiprocessing import Process, Pipe def f1(conn): # 管道的recv 里面不用写数字 from_main_proc ...
- timer event
/* linux/kernel/time/jiffies.c*/ static cycle_t jiffies_read(struct clocksource *cs) { return (cycle ...
- LeetCode(125) Valid Palindrome
题目 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ign ...