zoukankan      html  css  js  c++  java
  • POJ 2279

    线性DP

    本题的正解是杨氏矩阵与钩子定理
    但是这道题用DP的思想非常好
    img
    但是这样会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;
    }
    
  • 相关阅读:
    原码, 反码, 补码 详解
    位移运算符
    ASP.NET中httpmodules与httphandlers全解析
    MySQL count
    真正的能理解CSS中的line-height,height与line-height
    IfcEvent
    IfcWorkCalendarTypeEnum
    IfcSingleProjectInstance
    转换模型
    IfcTypeProduct
  • 原文地址:https://www.cnblogs.com/Mr-WolframsMgcBox/p/8578950.html
Copyright © 2011-2022 走看看