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

#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. websocket(python)

    1.websocket-server https://github.com/google/pywebsocket git clone https://github.com/google/pywebso ...

  2. Git中.gitignore文件不起作用

    Git中.gitignore文件不起作用的解决以及Git中的忽略规则介绍   在Studio里使用Git管理代码的过程中,可以修改.gitignore文件中的标示的方法来忽略开发者想忽略掉的文件或目录 ...

  3. Python3.5-20190505-廖老师-自我笔记字典和set

    字典:以键值对的形式存储数据.他就像字典一样,你可以查偏旁,直接跳到500页找到你想要的数据.但是列表就是从第一页开始一个一个的找,找到500页需要的时间很多. 所以字典就是查找速度快,但是所需要的空 ...

  4. python3.x filter,map,reduce浅析

    #map用法: #传递函数api进入map去执行,把字符串第一个字母变大写, #其他变小写返回 def format_name(s): s=s.lower() print(s) return s[0] ...

  5. 【leetcode】979. Distribute Coins in Binary Tree

    题目如下: Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and th ...

  6. Java8 map value排序

    /** * Map value降序排序 * @param map * @param <K> * @param <V> * @return LinkedHashMap */ pu ...

  7. django 如何重用app

    若有一个已经运行稳定的程序,那么可以将其打包,供其他项目安装使用. 假设django项目的目录结构如下: mysite/ manage.py mysite/ __init__.py settings. ...

  8. Python--nfs服务+计划任务crond服务+shell介绍

    nfs服务 NFS 是Network File System的缩写,即网络文件系统. 功能是通过网络让不同的机器.不同的操作系统能够彼此分享个别的数据,让应用程序在客户端通过网络访问位于服务器磁盘中的 ...

  9. .net从服务端下载文件(可以断点续传)

    public void DownFile(string guid) { var fileTransfer = new FileTransfer(); var directoryPath = Path. ...

  10. webpack 兼容低版本浏览器,转换ES6 ES7语法

    ES6,ES7真的太棒了,async +await+Promise,让我阅读代码的时候不用再从左拉到右了(异步太多,一层套一层真的太头痛) 但是有个问题,打包后低版本浏览器运行不了,还有我用了一些混淆 ...