[Noip simulation question] permutation (DP + high precision)

Source: Internet
Author: User

First, we can think like this:

Set status f [I, j] to 1 ~ Number of I sequence schemes with j '<'

So consider transfer

Because I is larger than the I-1, you can consider transferring from the I-1. First, I want to insert 1 ~ The I-1 of this sequence, so we can think about the Insertion Location:

For more information, see:

When the inserted position is '<', the answer will not change.

When the inserted position is '>', the answer will be + 1.

When the left boundary is inserted, the answer remains unchanged.

When the insert operation has a boundary, the answer is + 1.

So we know the number of '<' quantity and '>' of the previous I-1, then we can transfer it.

F [I, j] = (J + 1) * f [I-1, J] + (max {I-1-(J-1), 0} + 1) * f [I-1, j-1])

Then it is done with high precision ..

I did not speak about high-precision writing wrong places for a long time !!!!!!!!!!!!

Remember to clear the number of operations for each call !!!! That is, when assigning values, you must first clear them and then assign values !!!!!

# Include <cstdio> # include <cstring> # include <cmath> # include <string> # include <iostream> # include <algorithm> # include <queue> # include <set> # include <vector> # include <map> using namespace STD; typedef long ll; # define PII pair <int, int> # define mkpii make_pair <int, int> # define PDI pair <double, int> # define mkpdi make_pair <double, int> # define PLI pair <LL, int> # define mkpli make_pair <LL, int> # define rep (I, n) for (INT I = 0; I <(n); ++ I) # define for1 (I, A, n) for (INT I = (a); I <= (n); ++ I) # define for2 (I, A, n) for (INT I = (); I <(n); ++ I) # define for3 (I, A, n) for (INT I = (a); I> = (n); -- I) # define for4 (I, A, n) for (INT I = (a); I> (n); -- I) # define CC (I, A) memset (I, a, sizeof (I) # define read (A) A = getint () # define print (a) printf ("% d", a) # define dbg (X) cout <(# X) <"=" <(x) <Endl # define error (x )(! (X )? Puts ("error"): 0) # define printarr2 (a, B, c) for1 (_, 1, B) {for1 (__, 1, C) cout <A [_] [_]; cout <Endl ;}# define printarr1 (a, B) for1 (_, 1, B) cout <A [_] <'\ T'; cout <endlinline const int getint () {int r = 0, k = 1; char c = getchar (); for (; C <'0' | C> '9'; C = getchar () if (C = '-') k =-1; (; c> = '0' & C <= '9'; C = getchar () r = r * 10 + C-'0'; return K * r ;} inline const int max (const Int & A, const Int & B ){ Return A> B? A: B;} inline const int min (const Int & A, const Int & B) {return a <B? A: B;} const int n = 1155; int N, K; typedef int big [N]; big f [N], TP, TP2; void CLR (Big) {memset (A, 0, sizeof (INT) * (a [0] + 1); a [0] = 1;} void EQR (Big) {CLR (a); memcpy (A, TP, sizeof (INT) * (TP [0] + 1);} // clear void fix (Big A) first) {int I = A [0]; while (I> 1 &&! A [I]) -- I; A [0] = I;} void PR (Big A) {for3 (I, a [0], 1) printf ("% d", a [I]);} void MUL (Big A, int t) {CLR (TP); for1 (I, 1, a [0]) TP [I] = A [I] * t; int K = 0, I, SZ = A [0] + 32; for (I = 1; I <= SZ | K; ++ I) {TP [I] + = K; k = TP [I]/10; TP [I] % = 10 ;} TP [0] = I; fix (TP);} void PLS (Big A, Big B) {CLR (TP); int K = 0, I, SZ = max (A [0], B [0]); for (I = 1; I <= SZ | K; ++ I) {TP [I] = A [I] + B [I] + k; k = TP [I]/10; TP [I] % = 10 ;} TP [0] = I; fix (TP) ;}int main () {read (n); read (k); for1 (I, 0, K) CLR (F [I]); F [0] [1] = 1; for1 (I, 2, n) for3 (j, k, 0) {MUL (F [J], J + 1); EQR (F [J]); If (j> 0) {int T = max (0, i-1-j) + 1; mul (F [J-1], T); EQR (TP2); PLS (F [J], TP2); EQR (F [J]);} pr (F [k]); Return 0 ;}

  

 

 

 

 

[Description]

Arrange numbers 1 to n randomly, and insert ">" and "<" between each number according to their size relationship ".

Q: In all sorts, how many are arranged exactly with K "<".

For example, arrange (3, 4, 1, 5, 2)

3 <4> 1 <5> 2

There are 2 "<"


[Input format]

N, K


[Output format]

Answer


[Example input]

52

[Sample output]

66

[Data Scope]

20%: n <= 10

50%: the answer is within 0 .. 2 ^ 63-1.

100%: k <n <= 100

[Noip simulation question] permutation (DP + high precision)

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.