New task of sequencing workloads (SHOI2001)

Source: Internet
Author: User

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)

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.