博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU5322 Hope
阅读量:6909 次
发布时间:2019-06-27

本文共 3610 字,大约阅读时间需要 12 分钟。

 
给出一个排列,每个点向它右面离它最近的且比它大的点连无向边,每个连通块的价值为这个连通块大小的平方,每个排列的价值为所有连通块价值之积。求n个数的所有排列的价值之和。 
 

动态规划 花式递推/NTT加速

考虑到放完前i个数再放i+1,不管i+1放在哪里,i+1之前的数形成了一个连通块,且对之后的没有影响。

设f[i]表示一个大小为i的连通块,枚举其中最大的那个数的位置在第j个,得到方程:

   $ f[i]=\sum_{j=1}^{i} f[i-j] * j^2 * C(i-1,j-1)*(j-1)! $

       $  f[i]=(i-1)! *\sum_{j=1}^{i} j^2 * f[i-j] / (i-j)! $

最大的数在第j个位置时,j和它前面的所有数构成一个连通块,方案有$ C(i-1,j-1)*(j-1)! $种,贡献为j^2,j后面的连通块贡献为f[i-1]

此时复杂度为$O(n^2)$

接下来可以用数学方法花式递推,或者用分治NTT加速运算

 

(公式编辑器好像炸了……)

 

数学:

设k=i-j,上面的sum部分可以拆成三部分递推式

 

1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 #define LL long long 8 using namespace std; 9 const int mod=998244353;10 const int mxn=100005;11 LL dp[mxn],f1,f2,f3;12 LL inv[mxn],fac[mxn];13 void init(){14 inv[0]=inv[1]=1;15 fac[0]=fac[1]=1;16 for(int i=2;i

 

很优美对吧?

但这是一道NTT的练习题呀

不用NTT的话就没有意义!

分治NTT:

1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 #define LL long long 8 using namespace std; 9 const int mod=998244353;10 const int G=3;11 const int mxn=100010;12 int read(){13 int x=0,f=1;char ch=getchar();14 while(ch<'0' || ch>'9'){
if(ch=='-')f=-1;ch=getchar();}15 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}16 return x*f;17 }18 LL inv[mxn],fac[mxn];19 void init(){20 inv[0]=inv[1]=1;21 fac[0]=fac[1]=1;22 for(int i=2;i
>=1;35 }36 return res;37 }38 int N,len,rev[mxn<<1];39 LL a[mxn<<1],b[mxn<<1];40 LL f[mxn];41 void NTT(LL *a,int flag){42 for(int i=0;i
>1;67 solve(l,mid);68 int m=(mid-l+1)<<1;69 for(N=1,len=0;N<=m;N<<=1)len++;70 for(i=0;i
>1]>>1)|((i&1)<<(len-1));71 for(i=0;i

 

 

Hope is a good thing, which can help you conquer obstacles in your life, just keep fighting, and solve the problem below. 
In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. These differ from combinations, which are selections of some members of a set where order is disregarded. For example, written as tuples, there are six permutations of the set {1,2,3}, namely: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1). These are all the possible orderings of this three element set. As another example, an anagram of a word, all of whose letters are different, is a permutation of its letters. In this example, the letters are already ordered in the original word and the anagram is a reordering of the letters. 
There is a permutation 
A1,A2,...AnA1,A2,...An, now we define its value as below: 
For each 
AiAi, if there exists a minimum 
jj satisfies 
j>ij>i and 
Aj>AiAj>Ai , then connect an edge between 
AiAi and 
AjAj , so after we connect all the edges, there is a graph G, calculate the product of the number of nodes in each component as an integer P. The permutation value is P * P.Now, Mr. Zstu wants to know the sum of all the permutation value of n. In case the answer is very big, please output the answer mod 998244353. 
Just in case some of you can’t understand, all the permutations of 3 are 
1 2 3 
1 3 2 
2 3 1 
2 1 3 
3 1 2 
3 2 1 

InputThere are multiple test cases. 

There are no more than 10000 test cases. 
Each test case is an integer n(1n100000)(1≤n≤100000)
OutputFor each test case, output the answer as described above. 
Sample Input

12

Sample Output

15

Hint

 

转载于:https://www.cnblogs.com/SilverNebula/p/6783444.html

你可能感兴趣的文章
metabase实施文档
查看>>
10.3 定位连续值范围的开始点和结束点
查看>>
解析iscroll-小demo
查看>>
基站定位接口说明文档
查看>>
java实现邮件定时发送
查看>>
差分约束 【bzoj2330】[SCOI2011]糖果
查看>>
ArrayList和LinkedList区别
查看>>
Error_GL_KeyflexfieldDefinitionFactory.getStructureNumber无法找到应用产品
查看>>
js作用域及闭包
查看>>
CSS overflow 属性
查看>>
通过改变uiview的layer的frame来实现进度条
查看>>
ADB am 命令详细参数
查看>>
NOIp 数学基础
查看>>
nginx支持ipv6
查看>>
点名器
查看>>
Codeforces Problems-122A. Lucky Division
查看>>
移动端适配代码
查看>>
Js设置所有连接是触发/swt/的代码
查看>>
JS高级程序设计2nd部分知识要点1
查看>>
mac10.8 更新系统出错
查看>>