zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1173

    题意:

    The coach of a football team, after suffering for years the adverse comments of the media about his tactics, decides to take his revenge by presenting his players in a line-up in such a way that the TV cameras would be compelled to zigzag in a ridiculous bobbing motion, by alternating taller and shorter players. However, the team captain objects that he must be the first of the line by protocolary reasons, and that he wants to be seen in the best possible light: that is, he should not have a taller colleague next to him unless there is no alternative (everyone else is taller than him). Even in this case, the height difference should be as small as possible, while maintaining the zigzag arrangement of the line.

    With this condition the coach addresses an expert in computation (i.e. you) to help him find the number of different alignments he may make, knowing that all players have a different height. They are always numbered by stature starting by 1 as the shortest one. Of course the number of players may be arbitrary, provided it does not exceed 50.

    思路:

    Dp[i][j][0] 记录j开头, 长度为i,同时从大到小开始的顺序。
    Dp[i][j][1] 记录j开头, 长度为i,同时从小到大开始的顺序。
    对于Dp[i][j][0]累加Dp[i-1][k][1],其中k < j
    对于Dp[i][j][1]累加Dp[i-1][k][0],其中j <= k < i

    代码:

    // #include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<string.h>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const int MOD = 1e8+7;
    const int MAXN = 1e6+10;
    
    ULL Dp[55][55][2];
    int n, m;
    
    void Init()
    {
        memset(Dp, 0, sizeof(Dp));
        Dp[1][1][0] = Dp[1][1][1] = 1;
        for (int i = 2;i <= 50;i++)
        {
            for (int j = 1;j <= i;j++)
            {
                for (int k = 1;k < j;k++)
                    Dp[i][j][0] += Dp[i-1][k][1];
                for (int k = j;k < i;k++)
                    Dp[i][j][1] += Dp[i-1][k][0];
            }
        }
    }
    
    int main()
    {
        // freopen("test.in", "r", stdin);
        Init();
        int t, cas = 0;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cas);
            scanf("%d %d", &n, &m);
            ULL ans = 0;
            if (m == 1)
            {
                if (n <= 2)
                    ans += 1;
                else
                    ans += Dp[n-1][2][0];
            }
            else
            {
                for (int i = 1;i < m;i++)
                    ans += Dp[n-1][i][1];
            }
            printf(" %llu
    ", ans);
            
        }
    
        return 0;
    }
    
  • 相关阅读:
    (5)基于协同过滤推荐算法的图书推荐研究
    (4)推荐系统评测方法和指标分析
    (3)浅析机器学习在推荐系统中的应用
    (2)协同过滤推荐算法概述 摘要
    (1)推荐系统概述 -- 摘要
    30+简约时尚的Macbook贴花
    20+非常棒的Photoshop卡通设计教程
    20+WordPress手机主题和插件【好收藏推荐】
    30+WordPress古典风格的主题-古典却不失时尚
    配置FCKeditor_2.6.3+fckeditor-java-2.4
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12019271.html
Copyright © 2011-2022 走看看