[DP] Codeforces 840C .On the Bench
来源:互联网 发布:软件许可合同范本 编辑:程序博客网 时间:2024/05/22 12:42
%%%Vectorxj
#include <cstdio>#include <iostream>#include <algorithm>#include <map>#include <vector>using namespace std;const int N=610,P=1e9+7;int n,x,f[2][N];map<int,int> mp;vector<int> a;int fac[N],inv[N];inline int C(int x,int y){ return 1LL*fac[x]*inv[y]%P*inv[x-y]%P;}inline void add(int &x,int y){ if((x+=y)>=P) x-=P;}int main(){ freopen("1.in","r",stdin); freopen("1.out","w",stdout); scanf("%d",&n); fac[0]=inv[0]=inv[1]=1; for(int i=1;i<=600;i++) fac[i]=1LL*i*fac[i-1]%P; for(int i=2;i<=600;i++) inv[i]=1LL*(P-P/i)*inv[P%i]%P; for(int i=1;i<=600;i++) inv[i]=1LL*inv[i]*inv[i-1]%P; for(int i=1;i<=n;i++){ scanf("%d",&x); for(int j=2;j*j<=x;j++) while(x%(j*j)==0) x/=j*j; mp[x]++; } for(auto i : mp) a.push_back(i.second); int s=0,tot=a[0]; f[s][a[0]-1]=1; for(int g=1;g<a.size();g++,s^=1){ int nxt=a[g]; for(int i=0;i<=n;i++) f[s^1][i]=0; for(int i=0;i<tot;i++) for(int j=1;j<=nxt;j++) for(int k=0;k<=j && k<=i;k++) if(tot-i+1>=j-k) add(f[s^1][i-k+nxt-j],1LL*f[s][i]*C(i,k)%P*C(tot-i+1,j-k)%P*C(nxt-1,j-1)%P); tot+=nxt; } for(int i : a) f[s][0]=1LL*f[s][0]*fac[i]%P; printf("%d\n",f[s][0]); return 0;}
阅读全文
0 0
- [DP] Codeforces 840C .On the Bench
- Codeforces 840C On the Bench 【容斥+DP】
- codeforces 840C On the Bench 容斥+DP
- Codeforces-840C On the Bench(dp)
- codeforces840C On the Bench -- DP
- codeforces 840 C. On the Bench(多重集合的交错排列经典题目)
- CF840C On the Bench(dp+组合数学)
- codeforces Simba on the Circle (dp)
- Codeforces 840C [DP]
- Codeforces 280C Game on Tree 树形期望dp
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter (dp)
- Codeforces Round #286 C. Mr. Kitayuta, the Treasure Hunter dp
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
- Codeforces 689 C The Values You Can Make(dp)
- Codeforces 682C Alyona and the Tree DP
- Codeforces 687C The Values You Can Make DP
- Codeforces 842 C. Ilya And The Tree 树上dp
- error 2003 cant connect to mysql server on localhost 10061
- VC++编程实现修改EXE文件图标
- 关于JavaWeb开发中的基础知识点——resquest response
- 杂谈:坚持不是一种病态
- 欢迎使用CSDN-markdown编辑器
- [DP] Codeforces 840C .On the Bench
- 九度1045:百鸡问题
- UVALive
- Lua中日期和时间函数详解
- 一直以来对dispatch_sync的误区
- freeswitch系列三 SIP软电话xlite、linphonec接入kamailio+freeswitch
- xcodeDefault.xctoolchain/user/bin/swiftcfailed with exit code 1
- 基于FPGA的RGB565_YCbCr_Gray算法实现
- HDU 6170:Two strings