zoukankan      html  css  js  c++  java
  • A

    As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway. 

    InputThe input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file. 
    OutputFor each test case, you should output how many ways that all the trains can get out of the railway. 
    Sample Input

    1
    2
    3
    10

    Sample Output

    1
    2
    5
    16796

    Hint

    The result will be very large, so you may not process it by 32-bit integers.



     1 #include <iostream>
     2 #include <string.h>
     3 using namespace std;
     4 
     5 const int MAX = 305;
     6 int a[MAX][MAX];
     7 
     8 
     9 void chengf(int x,int i)
    10 {
    11     int temp = 0;;
    12     for(int j = 300;j >=0;j--)
    13     {
    14         temp = a[i-1][j]*x + temp;
    15         a[i][j] = temp % 10;
    16         temp = temp / 10;
    17 
    18     }
    19 }
    20 
    21 void chuf(int x,int i)
    22 {
    23     int temp = 0;
    24     for(int j = 0;j <=300;j++)
    25     {
    26         temp = temp *10 + a[i][j];
    27         a[i][j] = temp / x;
    28         temp = temp %x;
    29     }
    30 }
    31 
    32 void DP()
    33 {
    34     memset(a,0,sizeof(a));
    35     a[1][300] = 1;
    36     for(int i = 2;i <= 100;i++)
    37     {
    38         int temp = 4*i - 2;
    39         chengf(temp,i);
    40         temp = i + 1;
    41         chuf(temp,i);
    42     }
    43 }
    44 
    45 int main()
    46 {
    47    int n;
    48    DP();
    49    while(cin>>n)
    50    {
    51        int temp = 0;
    52         for(int i = 0;i <= 300;i++)
    53         {
    54             if(a[n][i]!=0)
    55             {
    56                 temp = i;
    57                 break;
    58             }
    59         }
    60         for(int i = temp;i <=300;i++)
    61             cout<<a[n][i];
    62         cout<<endl;
    63 
    64    }
    65 
    66     return 0;
    67 }
     
  • 相关阅读:
    [Android Pro] Android源码编译之Nexus5真机编译
    [设计模式] 策略模式(Strategy)
    [Android] Anreoid repo 切换分支
    [Android] repo 下载Android源码(国内镜像)
    [Android] osx下如何使用SublimeText阅读Android系统源码
    [Ubuntu] ubuntu的tty下挂载移动硬盘拷贝数据
    Elasticsearch
    Flink简介
    SQL中instr和like的使用区别
    count(1) 与 count(*) 比较
  • 原文地址:https://www.cnblogs.com/a2985812043/p/7263180.html
Copyright © 2011-2022 走看看