zoukankan      html  css  js  c++  java
  • hdu5322 Hope(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

    Hope

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 116    Accepted Submission(s): 44


    Problem Description
    Hope is a good thing, which can help you conquer obstacles in your life, just keep fighting, and solve the problem below.



    In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. These differ from combinations, which are selections of some members of a set where order is disregarded. For example, written as tuples, there are six permutations of the set {1,2,3}, namely: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1). These are all the possible orderings of this three element set. As another example, an anagram of a word, all of whose letters are different, is a permutation of its letters. In this example, the letters are already ordered in the original word and the anagram is a reordering of the letters. 
    There is a permutation A1,A2,...An, now we define its value as below:
    For each Ai, if there exists a minimum j satisfies j>i and Aj>Ai , then connect an edge between Ai and Aj , so after we connect all the edges, there is a graph G, calculate the product of the number of nodes in each component as an integer P. The permutation value is P * P.Now, Mr. Zstu wants to know the sum of all the permutation value of n. In case the answer is very big, please output the answer mod 998244353.
    Just in case some of you can’t understand, all the permutations of 3 are
    1 2 3
    1 3 2
    2 3 1
    2 1 3
    3 1 2
    3 2 1
     
    Input
    There are multiple test cases.
    There are no more than 10000 test cases.
    Each test case is an integer n(1n100000).
     
    Output
    For each test case, output the answer as described above.

     
    Sample Input
    1 2
     
    Sample Output
    1 5

    dp

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define MOD 998244353
     4 long long dp[100010];
     5 int main()
     6 {
     7     int n;
     8     dp[0] = 1;
     9     dp[1] = 1;
    10     dp[2] = 5;
    11     for(long long i=0;i<=100000;i++)dp[i+3] = (((3*i+7)*dp[i+2] - (i+2)*(3*i+2)%MOD*dp[i+1] + (i+2)*(i+1)%MOD*i%MOD*dp[i])%MOD + MOD )%MOD;
    12     while(scanf("%d",&n)!=EOF) {
    13         printf("%I64d
    ", dp[n]);
    14     }
    15     return 0;
    16 }
  • 相关阅读:
    CocoaPods
    Git
    LLVM
    浅入浅出数据结构(11)——简要介绍算法时间复杂度
    浅入浅出数据结构(10)——树的简介
    浅入浅出数据结构(8)——栈、后缀表达式与四则运算计算器
    浅入浅出数据结构(7)——特殊的表:队列与栈
    浅入浅出数据结构(6)——游标数组及其实现
    浅入浅出数据结构(5)——链表的操作
    浅入浅出数据结构(4)——线性表与链表
  • 原文地址:https://www.cnblogs.com/fraud/p/4686989.html
Copyright © 2011-2022 走看看