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 ...
随机推荐
- 如何让Sublime Text编辑器支持新的ABAP关键字
ABAP 7.40推出了许多新的关键字 - keyword,您的Sublime Text可能无法针对这些新关键字实现期望的语法高亮显示(syntax highlight)或者自动完成(auto com ...
- 100行代码让您学会JavaScript原生的Proxy设计模式
面向对象设计里的设计模式之Proxy(代理)模式,相信很多朋友已经很熟悉了.比如我之前写过代理模式在Java中实现的两篇文章: Java代理设计模式(Proxy)的四种具体实现:静态代理和动态代理 J ...
- Xcode - 'openssl/opensslconf.h' file not found解决
点击Build Settings搜索Header Search Paths,添加$(SRCROOT)/目录/Alipay
- couldn't be opened because you don't have permission to view it” 解决方法
I use Xcode6 GM. I encountered the same problem. What I did was to go to Build Options. Then I chang ...
- hdu 6058 Kanade's sum (计算贡献,思维)
题意: 给你一个全排列,要你求这个序列的所有区间的第k大的和 思路:比赛的时候一看就知道肯定是算贡献,也知道是枚举每个数,然后看他在多少个区间是第K大,然后计算他的贡献就可以了,但是没有找到如何在o( ...
- angstromctf -No libc for You
0x00 syscall syscall函数原型为: int syscall(int number, ...) 其中number是系统调用号,number后面应顺序接上该系统调用的所有参数.大概意思是 ...
- OpenCV Haar AdaBoost源码改进据说是比EMCV快6倍
<pre name="code" class="cpp">#include "Haar.h" #include "lo ...
- JS任意文件转base64
<!doctype html><html><head><meta charset="utf-8"><meta name=&qu ...
- xhEditor编辑器上传图片到 OSS
前段时间,公司在项目上用到了xhEditor编辑器来给用户做一个上传图片的功能当时做的时候觉得很有意思,想想 基本的用户图片上传到自己服务器,还有点小占地方: 后来....然后直接上传到阿里云 .接下 ...
- windows 下phpstudy 升级mysql版本5.7
今天在导入sql文件的时候遇到了sql执行错误.最后找到原因是因为mysql版本过低,导致出错 原因:在执行sql的时候出现了两次CURRENT_TIMESTAMP ,最后得知在5.7版本之前都是不支 ...