【做题】Codeforces Round #429 (Div. 2) E. On the Bench——组合问题+dp
#include<bits/stdc++.h>
using namespace std;
const int N=,MOD=;
long long num[N],c[N][N];
long long dp[N][N],a[N];
int tmp,n,tot,example[N];
bool key;
bool ask(int x,int y)
{
long long re=;
re*=x;
re*=y;
long long f=sqrt(re);
if(f*f==re) return ;
return ;
}
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>tmp;
key=;
for(int j=;j<=tot;j++)
{
if(ask(tmp,example[j]))
{
num[j]++;
key=;
break;
}
}
if(key)
{
num[++tot]=;
example[tot]=tmp;
}
}
for(int i=;i<=n;i++)
c[i][]=;
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
{
c[i][j]=c[i-][j]+c[i-][j-];
c[i][j]%=MOD;
}
int m=;
a[]=;
for(int i=;i<=n;i++)
{
a[i]=a[i-]*i;
a[i]%=MOD;
}
dp[][]=;
long long temp,temp1;
for(int i=;i<=tot;i++)
{
for(int j=;j<n&&j<=m+;j++)
{
if(dp[i-][j]==) continue;
for(int k=;k<num[i];k++)
{
temp=dp[i-][j]*c[num[i]-][k];temp%=MOD;
for(int p=;p<=k+&&p<=j+num[i]--k;p++)
{
temp1=temp*c[j][p];temp1%=MOD;//本人因为数据溢出炸了几次
dp[i][j+num[i]--k-p]+=(temp1*c[m+-j][k+-p])%MOD;
dp[i][j+num[i]--k-p]%=MOD;
}
}
}
m+=num[i];
}
for(int i=;i<=tot;i++)
{
dp[tot][]*=a[num[i]];
dp[tot][]%=MOD;
}
cout<<dp[tot][]<<endl;
return ;
}
【做题】Codeforces Round #429 (Div. 2) E. On the Bench——组合问题+dp的更多相关文章
- Codeforces Round #429 (Div. 2) E. On the Bench
E. On the Bench time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #429 (Div. 1) C. On the Bench(dp + 组合数)
题意 一个长度为 \(n\) 的序列 \(A\) ,定义一个 \(1\) 到 \(n\) 的排列 \(p\) 是合法的,当且仅当 \(\forall i \in [1, n − 1], A_{p_i} ...
- CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)
思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组, ...
- CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上 ...
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
- 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas
题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
随机推荐
- java中二维数组的复制克隆
https://blog.csdn.net/qq_37232304/article/details/79950022
- linux整理
文件查看命令 cat [OPTION]... [FILE]... - E: 显示行结束符$ -n: 对显示出的每一行进行编号 -A:显示所有控制符 -b:非空行编号 -s:压缩连续的空行成一行 he ...
- javascript(一):javascript基本介绍及基本语法
什么是javascript? javascript是一种直译型脚本语言,是一种动态类型.弱类型.基于原型的语言.(所谓“脚本语言”:指的是它不具有开发操作系统的能力,只是用来编写大型运用程序的脚本!) ...
- CentOS 5 yum源无法使用
在新装的CentOS 5.7系统中,由于CentOS 5.7版本比较旧,yum源无法使用. 尝试多种方法,最终从http://blog.csdn.net/zhuix7788/article/detai ...
- C#操作XML方法详解
using System.Xml; //初始化一个xml实例 XmlDocument xml=new XmlDocument(); //导入指定xml文件 xml.Load(path); xml. ...
- 【Redis学习之六】Redis数据类型:集合和有序集合
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 redis-2.8.18 一.集合 Set无序的.去重的元素 ...
- linux下安装mysql(rpm文件安装)
数据库包下载: https://www.mysql.com/downloads/ 在GPL开原协议的社区开源版里边下载 我们用mysql community server里边的 其中workbench ...
- c# 使用checked和unchecked
首先要知道int型在c#中是一个32位的数.由此可以知道int型的取值范围是(-2147483648~2147483647)当要使用int的最小值或者是最大值的时候,可以使用int.MinValue和 ...
- WebStorm: The Smartest JavaScript IDE by JetBrains
WebStorm: The Smartest JavaScript IDE by JetBrains https://www.jetbrains.com/webstorm/?fromMenu
- highchart 柱状图 分组样例
var chart = Highcharts.chart('container',{ chart: { type: 'column' }, title: { text: '月平均降雨量' }, sub ...