New task of sequencing workloads (SHOI2001)
Given two integers n and T, the number of reverse logarithm is t in the full permutation of N, and the smallest full permutation of the dictionary order of the inverse logarithm is t.
First, the first problem can be resolved with DP,\ (f[i][j]\) represents the number of first I, J reverse pairs of sequential numbers, then \ (f[i][j]=f[i-1][j-k]\ (K<i) (K\le j) \).
Easy to prove a full array, exchange value difference 1 of two number, reverse the number of + or-1. At the same time can be introduced in reverse order of the logarithm of the dictionary of the minimum full array, a strict rise, a tolerance of 1 sequence, followed by two strict descent, the tolerance is 1 of the sequence, and the following two sequence convergence difference 2. Therefore, from the back-to-front processing, the current number and the next number can be exchanged. See the code for specifics.
#include <cstdio>#include <algorithm>using namespaceStdConst intmaxn= -;intN, T;Long LongF[MAXN][MAXN*MAXN];intA[MAXN];intMain () {scanf ("%d%d", &n, &t);if(t==0) {puts ("1"); for(intI=1; i<=n; ++i) printf ("%d ", i);return 0; } f[1][0]=f[2][0]=f[2][1]=1; for(intI=3; i<=n; ++i) for(intj=0; j<=i* (i-1)/2; ++J) for(intk=0; k<i&&k<=j; ++K) F[i][j]+=f[i-1][J-K]; printf"%lld\n", F[n][t]); for(intI=1; i<=n; ++i) a[i]=i; for(intI=n-1; i>=1; -I.) { for(intJ=n; j>i; --J) {swap (A[i], a[j]);if(! (--T)) Break; }if(!t) Break; } for(intI=1; i<=n; ++i) printf ("%d ", A[i]);return 0;}
New task of sequencing workloads (SHOI2001)