codeforces840C On the Bench -- DP
来源:互联网 发布:喜马拉雅山攀登 知乎 编辑:程序博客网 时间:2024/05/29 07:55
%%%Vectorxj
代码
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define N 310#define M 1000000007int i,j,k,n,m,p,v[N],l,a[N],x,y,t,f[2][N],s;int c[N][N];int Ans;int* g;bool b;int main(){ scanf("%d",&n); for(i=c[0][0]=1;i<=n;i++)c[i][0]=1; for(i=1;i<=n;i++) for(j=1;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%M; for(i=1;i<=n;i++){ scanf("%d",&x); for(j=2;(t=j*j)<=x;j++) while(!(x%t))x/=t; a[i]=x; } sort(a+1,a+n+1); for(i=1;i<=n;i=j+1){ for(j=i;a[j+1]==a[j];j++); v[++l]=j-i+1; } sort(v+1,v+l+1); f[0][(t=v[l])-1]=1; for(p=l-1;p;p--,b^=1){ s=v[p];g=f[b^1]; for(i=0;i<=t+s;i++)g[i]=0; for(i=0;i<t;i++){ x=f[b][i]; if(x){ for(j=1;j<=s;j++) for(k=0;k<=i&&k<=j;k++) if(t-i+1>=j-k){ (g[i-k+s-j]+=1ll*x*c[i][k]%M*c[s-1][j-1]%M*c[t-i+1][j-k]%M)%=M; } } } t+=s; } Ans=f[b][0]; for(i=1;i<=l;i++) for(j=2;j<=v[i];j++) Ans=1ll*Ans*j%M; cout<<Ans<<endl; return 0;}
阅读全文
0 0
- codeforces840C On the Bench -- DP
- [DP] Codeforces 840C .On the Bench
- CF840C On the Bench(dp+组合数学)
- Codeforces 840C On the Bench 【容斥+DP】
- codeforces 840C On the Bench 容斥+DP
- Codeforces-840C On the Bench(dp)
- codeforces 840 C. On the Bench(多重集合的交错排列经典题目)
- dp(uva590Always on the run)
- HDU3848 CC On The Tree, 树形DP
- usaco Home on the Range java ---DP
- uva_590_Always on the run (普通DP)
- UVA 590 - Always on the run (dp)
- poj3042 Grazing on the Run[区间dp]
- UVA 590 Always on the run(dp)
- uva 590 Always on the run(dp)
- UVA 590 Always on the run | dp
- Always on the run - UVa 590 dp
- hdu4916 Count on the path,树dp
- JSONP实现跨域请求JSON数据
- 【tomcat】tomcat常见操作记录
- 日常(抗日神剧_扫雷)
- 无限轮播 RollViewPager 的简单使用
- fragment加载
- codeforces840C On the Bench -- DP
- python3.4 获取cookie后继续访问其他页面
- java提高篇(五)-----抽象类与接口
- 输出字典的键(key)
- 给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起来。
- 字典树
- vittualbox5.1 自动挂载共享文件夹
- Maven的核心概念
- ajax