因为不会打公式,随意就先将就一下?

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=;
const int MOD=1e9+;
int add (int x,int y) {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y) {return (LL)x*y%MOD;}
int dec (int x,int y) {x=x-y;return x<?x+MOD:x;}
int Pow (int x,int y)
{
if (y==) return ;
if (y==) return x;
int lalal=Pow(x,y>>);
lalal=mul(lalal,lalal);
if (y&) lalal=mul(lalal,x);
return lalal;
}
int n,m;
int g[N][N][N][];
int h[N][N][N];
int JC[N];
void Init (int n)
{
memset(g,,sizeof(g));
g[][][][]=;g[][][][]=;g[][][][]=;
JC[]=;for (int u=;u<=n;u++) JC[u]=mul(JC[u-],u);
for (int u=;u<=n;u++)
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
for (int k=;k<=;k++) if (g[u][i][j][k])
{
if (k!=) g[u+][i][j][]=add(g[u+][i][j][],g[u][i][j][k]);
if (k!=) g[u][i+][j][]=add(g[u][i+][j][],g[u][i][j][k]);
if (k!=) g[u][i][j+][]=add(g[u][i][j+][],g[u][i][j][k]);
int now=mul(mul(mul(JC[u],JC[i]),JC[j]),g[u][i][j][k]);
//if (u==2&&i==1&&j==0) printf("%d %d\n",g[u][i][j][k],(mul(JC[u],JC[i]),JC[j]));
h[u][i][j]=add(h[u][i][j],now);
}
//printf("%d\n",h[2][1][0]);
}
vector<int> vec[N];
int f[][N][];
int sum[];
int d[N][N][];
int main()
{
Init();
scanf("%d%d",&n,&m);
for (int u=;u<=n;u++)
{
int t,g;
scanf("%d%d",&t,&g);
sum[g-]+=t;vec[g-].push_back(t);
}
if (sum[]>sum[]) {swap(sum[],sum[]);swap(vec[],vec[]);}
if (sum[]>sum[]) {swap(sum[],sum[]);swap(vec[],vec[]);}
for (int u=;u<=;u++)
{
int siz=vec[u].size();
f[u][][]=;
for (int i=;i<siz;i++)
for (int j=i+;j>=;j--)
for (int k=sum[u];k>=vec[u][i];k--)
f[u][j][k]=add(f[u][j][k],f[u][j-][k-vec[u][i]]);
}
for (int u=;u<=vec[].size();u++)
for (int j=;j<=sum[];j++) if (f[][u][j])
for (int i=;i<=vec[].size();i++)
for (int k=;k<=sum[];k++) if (f[][i][k])
d[u][i][j+k]=add(d[u][i][j+k],mul(f[][u][j],f[][i][k]));
int ans=;
for (int u=;u<=vec[].size();u++)
for (int i=;i<=sum[];i++) if (f[][u][i])
{
int t=m-i;
for (int j=;j<=vec[].size();j++)
for (int k=;k<=vec[].size();k++)
ans=add(ans,mul(h[u][j][k],(mul(d[j][k][t],f[][u][i]))));
}
printf("%d\n",ans);
return ;
}

Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)的更多相关文章

  1. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  2. Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)

    链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...

  3. Codeforces Round #568 (Div. 2) B. Email from Polycarp

    链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...

  4. Codeforces Round #568 (Div. 2)A

    A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...

  5. Codeforces Round #568 (Div. 2) A.Ropewalkers

    链接: https://codeforces.com/contest/1185/problem/A 题意: Polycarp decided to relax on his weekend and v ...

  6. Codeforces Round #568 (Div. 2) 选做

    A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...

  7. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  8. Codeforces Round #568 (Div. 2)B

    B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an e ...

  9. codeforces Round #568(Div.2)A B C

    有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...

随机推荐

  1. 关于GeneXus封装方法Model的方法

     最近 刚从外地出差回来 工作任务不是很重 能够抽点时间记点东西 下午花了2个多钟头尝试了一下GeneXus的封装方法的功能,这里记一下便于自己以后查看.我们在许多项目中或多或少都会有着重复代码编写的 ...

  2. LNMP环境安装

    一.LNMP 1.使用LNMP的优点: 资源占用少 更多并发 代理服务器 热启动 稳定高效 负载均衡 邮件服务器 2.安装前准备: 2.1查看防火墙(默认开启): [root@localhost ~] ...

  3. Docker基础(上)

    Docker基础(上) 链接:https://pan.baidu.com/s/1KQjKml2OZAReYwOvpWD9XQ 提取码:6vo8 复制这段内容后打开百度网盘手机App,操作更方便哦 1. ...

  4. 转载:HTTP详解

    第一部分: 1. HTTP简介 HTTP 协议(HyperText Transfer Protocol,超文本传输协议)是用于从WWW服务器传输超文本到本地浏览器的传送协议.它可以使浏览器更加高效,使 ...

  5. 三、JPA增删改查常用方法

    前言:创建EntityManager对象,需要先创建创建EntityManagerFactory对象 方式一:直接通过persistenceUnitName创建 String persistenceU ...

  6. 如何限制只有某些IP才能使用Tomcat Manager

    只有指定的主机或IP地址才可以访问部署在Tomcat下的应用.Tomcat提供了两个参数供你配置:RemoteHostValve 和RemoteAddrValve,前者用于限制主机名,后者用于限制IP ...

  7. foobar2000 频谱给我的win10 任务栏添加一点会动背景

    在任务栏右键,"任务栏设置",颜色 -> 透明效果, 然后 foobar2000 的 view -> layout -> Quick Setup,选择带有Visu ...

  8. c++后台开发面试常见知识点总结(四)数据库

    数据库的索引类型 聚集索引和非聚集索引的区别(叶节点存储内容) 唯一性索引和主码索引的区别 索引的优缺点,什么时候使用索引,什么时候不能使用索引(重点) 索引最左前缀问题 数据库中事务的ACID 数据 ...

  9. python3.x 匿名函数lambda_扩展sort

    #匿名函数lambda 参数: 表达式关键字 lambda 说明它是一个匿名函数,冒号 : 前面的变量是该匿名函数的参数,冒号后面是函数的返回值,注意这里不需使用 return 关键字. ambda只 ...

  10. PHP curl_reset函数

    curl_reset— 重置libcurl会话句柄的所有选项. 说明 void curl_reset ( resource $ch ) 该函数将重新初始化cURL的所有选项值(默认值). 注意:cur ...