zoukankan      html  css  js  c++  java
  • HDU 2861 四维dp打表

    Patti and Terri run a bar in which there are 15 stools. One day, Darrell entered the bar and found that the situation how customers chose the stools were as follows:
    OOEOOOOEEEOOOEO
    O means that the stool in a certain position is used, while E means that the stool in a certain position is empty (here what we care is not who sits on the stool, but whether the stool is empty).As the example we show above, we can say the situation how the 15 stools is used determines 7 intervals (as following):
    OO E OOOO EEE OOO E O
    Now we postulate that there are N stools and M customers, which make up K intervals. How many arrangements do you think will satisfy the condition?
     
    Input
    There are multi test cases and for each test case:
    Each case contains three integers N (0<N<=200), M (M<=N), K (K<=20).
     
    Output
    For each test case print the number of arrangements as described above. (All answers is fit in 64-bit.)
     
    Sample Input
    3 1 3 4 2 4
     
    Sample Output
    1 2
     
     
     
    n个位置坐了m个人分成了k块,求所有可能的种数;
    关键是dp表达式
    i 0-200
    j 0-200
    k 1-20

    dp[i+1][j][k][0]=dp[i][j][k][0]+dp[i][j][k-1][1];

    dp[i+1][j][k][1]=dp[i][j-1][k-1][0]+dp[i][j-1][k][1];

    打表然后查询输出

    #include<iostream>
    #include<cstdio>
    using namespace std;
    long long dp[202][202][22][2];
    int main()
    {
        int n=200,m=200,ak=20,i,j,k;
        dp[0][0][0][1]=1;
        dp[0][0][0][0]=1;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=m;j++)
            {
                for(k=1;k<=ak;k++)
                {
                    dp[i+1][j][k][0]=dp[i][j][k][0]+dp[i][j][k-1][1];
                    if(j!=0)
                    dp[i+1][j][k][1]=dp[i][j-1][k-1][0]+dp[i][j-1][k][1];
                }
            }
        }
        while(scanf("%d%d%d",&n,&m,&ak)!=EOF)
        {
            cout<<dp[n][m][ak][0]+dp[n][m][ak][1]<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Windows下升级Zabbix Agent
    mariadb+haproxy实现负载均衡(一)
    mariadb数据库galera下添加新的服务器节点
    1044/1045
    mariadb 离线安装
    CentSO7.6下部署Maridb Galera Cluster 实践记录(一)
    Word 远程调用失败:异常来自 HRESULT:0x800706BE
    CentSO7.6下部署Maridb Galera Cluster 实践记录(二)
    数据结构之双向链表-c语言实现
    数据结构之单链表-c语言实现
  • 原文地址:https://www.cnblogs.com/dzzy/p/5216106.html
Copyright © 2011-2022 走看看