zoukankan      html  css  js  c++  java
  • dp(传球)

    https://ac.nowcoder.com/acm/contest/1126/B

    链接:https://ac.nowcoder.com/acm/contest/1126/B
    来源:牛客网

    上体育课的时候,小蛮的老师经常带着同学们一起做游戏。这次,老师带着同学们一起做传球游戏。
    游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同学可以把球传给自己左右的两个同学中的一个(左右任意),当老师再次吹哨子时,传球停止,此时,拿着球没传出去的那个同学就是败者,要给大家表演一个节目。
    聪明的小蛮提出一个有趣的问题:有多少种不同的传球方法可以使得从小蛮手里开始传的球,传了m次以后,又回到小蛮手里。两种传球的方法被视作不同的方法,当且仅当这两种方法中,接到球的同学按接球顺序组成的序列是不同的。比如有3个同学1号、2号、3号,并假设小蛮为1号,球传了3次回到小蛮手里的方式有1->2->3->1和1->3->2->1,共2种。

    输入描述:

    共一行,有两个用空格隔开的整数n,m( 3 ≤ n ≤ 30,1 ≤ m ≤ 30 )。

    输出描述:

    共一行,有一个整数,表示符合题意的方法数。
    示例1

    输入

    复制
    3 3

    输出

    复制
    2

    备注:

    40%的数据满足:3 ≤ n ≤ 30,1 ≤ m ≤ 20;
    100%的数据满足:3 ≤ n ≤ 30,1 ≤ m ≤ 30。
    //#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <stdio.h>
    #include <queue>
    #include <stack>;
    #include <map>
    #include <set>
    #include <string.h>
    #include <vector>
    #define ME(x , y) memset(x , y , sizeof(x))
    #define SF(n) scanf("%d" , &n)
    #define rep(i , n) for(int i = 0 ; i < n ; i ++)
    #define INF  0x3f3f3f3f
    #define mod 998244353
    #define PI acos(-1)
    using namespace std;
    typedef long long ll ;
    int dp[39][39];//i为走的步数,j为编号。
    
    int main()
    {
    
        int n , m ;
        scanf("%d%d" , &n , &m);
        dp[0][1] = 1 ;
        for(int i = 1 ; i <= m ; i++)
        {
            for(int j = 1 ; j <= n ; j++)
            {
                if(j == 1)
                    dp[i][j] = dp[i-1][n] + dp[i-1][2];
                else if(j == n)
                    dp[i][j] = dp[i-1][1] + dp[i-1][n-1];
                else
                {
                    dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1];
                }
            }
        }
        cout << dp[m][1] << endl ;
        return 0 ;
    }
  • 相关阅读:
    CodeForces
    CodeForces
    AtCoder
    AtCoder
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    Centos7配置yum国内镜像及仓库升级
    环境变量
  • 原文地址:https://www.cnblogs.com/nonames/p/11732954.html
Copyright © 2011-2022 走看看