【做题】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 ...
随机推荐
- gedit emacs
emacs常用操作: 1)C-g:退出当前命令 2)C-x C-f:搜索文件打开 3)C-s:向前搜索 C-r:向后搜索 4)C-x 2:水平分割窗口 C-x 3:竖直分割窗口 5)C-x o:切换窗 ...
- C#基础知识整理
年时,北风吹雁雪纷纷,一条秋裤冻上头.冷的连手都懒得动,就随便翻翻书,也没有更新博客,如今年已过,开始投入到正常的工作状态中,趁现在需求还没有来,把C#基础知识梳理一下,其实一直以来就想这样做的,对于 ...
- 【Redis学习之七】Redis持久化
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 redis-2.8.18 什么是持久化? 将数据从掉电易失的 ...
- 【Hbase学习之三】Hbase Java API
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-2.6.5 hbase-0.98.12.1-h ...
- QtCreator 调试源码
[1]安装源码 声明:要想调试进入Qt源码,必须首先保证我们安装了Qt源码.下面说明安装Qt源码注意事项. 一般安装过程(默认不安装源码): 安装源码过程(需要自己设置,点击“全选”): 综上所述:Q ...
- jack welch:“你们知道了,但是我们做到了”
一.我们发现,只要我们敢于相信自己,敢于朝着那些看似不可能的目标不懈努力,最终会如愿以偿,个人的领袖形象也将因此而确立. 二.一个领导者必须要有魄力.对我来说,这就是一个人能否领导一项业务的分水岭. ...
- USMART 组件移植到STM32
USMART是由ALIENTEK开发的一个串口调试助手组件,通过它可以通过串口调试助手,调用程序里面的任何函数并执行,单个函数最多支持10个输入参数,并支持函数返回值显示. USMART支持的参数类型 ...
- Python数据类型深入学习之数字
一. 数字常量 1. 下面来看看Python的数字常量中都要哪些类型: 数字 常量 129,-89,0 一般整数 9999848499999L,4594646469l 长整型数(无限大小) 1.232 ...
- 以太坊客户端Ethereum Wallet与Geth区别简介
以太坊客户端Ethereum Wallet与Geth区别简介 最近有不少朋友在搭建交易平台,在咨询和技术交流的过程中发现很多朋友不太清楚Ethereum Wallet和Geth区别.甚至有朋友使用Ge ...
- js定时器优化
在js中如果打算使用setInterval进行倒数,计时等功能,往往是不准确的,因为setInterval的回调函数并不是到时后立即执行,而是等系统计算资源空闲下来后才会执行.而下一次触发时间则是在s ...