线性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的更多相关文章

  1. 轮廓线DP:poj 2279 Mr. Young's Picture Permutations

    poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...

  2. [POJ 2279] Mr. Young's Picture Permutations

    [题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...

  3. 【杨氏矩阵+勾长公式】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 ...

  4. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  5. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  6. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  7. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  8. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  9. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

随机推荐

  1. 状态压缩---区间dp第一题

    标签: ACM 题目 Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is ...

  2. 2006: C语言实验——拍皮球

    2006: C语言实验——拍皮球 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 231  Solved: 162[Submit][Status][Web ...

  3. PJSIP-iOS源码编译

    官方文档https://trac.pjsip.org/repos/wiki/Getting-Started/iPhone 功能 在iPhone上可以实现的功能: 包含基于CoreAudio的音频设备, ...

  4. GYM 101604 || 20181010

    看着前面咕咕咕的国庆集训 难受 十月十日要萌一天哇www A.字符串 题意:给定一个字符串 问能否交换两个字符或者不交换字符,使其成为回文串 之前写的太丑 重写一遍加一堆 if 竟然过了w 思路:求出 ...

  5. Lucene原理与代码分析

    http://www.cnblogs.com/forfuture1978/category/300665.html

  6. NSLayoutConstraint.constraintsWithVisualFormat详解,以及AlignAllCenterY

    NSLayoutConstraint.constraintsWithVisualFormat详解,以及AlignAllCenterY 转载2015-07-08 18:02:02 鉴于苹果官方文档的解释 ...

  7. MySQLfailover错误一则

    由于公司现有主库要转移到新的主库上,所以,我打算利用MySQLfailover工具的故障转移. 1.开发把程序账号转移到新主库上 2.停止现有主库,使之进行故障转移,转移期间会自动锁表,保持数据一致性 ...

  8. 纯 CSS 创作一个小球绕着圆环盘旋的动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/gKxyWo 可交互视频 ...

  9. laravel中的视图合成器

    ==================================================================================================== ...

  10. 设置 TabBarItemt图片颜色

    UIImage *discussSelectedImage = [UIImage imageNamed:@"discuss_selected"];//设置图片不渲染 discuss ...