Agc005d~k Perm Counting

Source: Internet
Author: User
Tags abs valid
Main Topic

Ask how many of the 1~n in the arrangement, so that abs (the value of the first position −i)!=k a B s (the value of the first position −i)! = k ABS (value I position-i)!=k thinking of solving problems

Consider tolerance, ans=∑ni=0 (−1) ig[i] (n−i)! (G[i] indicates that at least I position is not a valid number of scenarios) a n s =∑i = 0 N (−1) i g [i] (n−i)! (g [I] indicates that at least I position is not a valid number of scenarios) Ans=\sum_{i=0}^{n} ( -1) ^ig[i] (n-i)! (G[i] indicates that at least I position is not a valid number of scenarios)
Consider how to ask for G[i]
Place each position and each value as a point, there are 2n points, if I position can not fill J, position I to value J edge.
In this way, a binary graph is obtained, and the problem becomes the number of options to select the I side.
Each strand of the dichotomy is pulled out and together, the 2n points are formed in a row, and some adjacent points have edges.
Set F[I][J][0/1] f [i] [j] [0/1] F[I][J][0/1], that is, to the first point, the J-Edge is selected, the point and the edge of the last point whether there is a choice (if there is no edge of 0) of the scheme number.
So g[i]=f[2n][i]][0]+f[2n][i][1] g [i] = f [2 n] [i]] [0] + F [2 n] [i] [1] g[i]=f[2n][i]][0]+f[2n][i][1]

 #include <cmath> #include <iostream> #include <cstdio> #include < cstdlib> #include <cstring> #include <algorithm> #include <queue> #include <map> #include
<bitset> #include <set> const int inf=2147483647; 
const int mo=924844033;
const int n=4005;
using namespace Std;
int N,m,tot;
BOOL Lk[n]; Long 

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.