Example 10-14 Competition ranking UVa12034

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Solving ideas: The problem is solved by looking for a recursive relationship. The final answer is F (n). Assuming that the first person has I, there is C (n,i) possible, then there is the possibility of f (n-i). The final answer is ∑c (n,i) F (n-i) (I starting from 1).

3. Code:

#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 1000+10#define MOD 10056int c[n ][n];int f[n];int n;void init () {c[0][0] = f[0] = 1;for (int i = 1; i <=; i++) {c[i][0] = c[i][i]=1;f[i] = 0;for (in T j = 1; J < I; J + +) C[i][j] = (C[i-1][j-1] + c[i-1][j])%mod;for (int j = 1; J <= I; j + +) F[i] = (F[i] + c[i][j] * f[i-j]%mod)% MOD;}}  int main () {freopen ("test.txt", "R", stdin), int cnt = 0;init (), int t;cin >> t;while (t--) {cin >> n;printf ("case %d: ", ++cnt); cout << f[n] << Endl;} return 0;}



Example 10-14 Contest ranking UVa12034

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.