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

#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. 【转】Java里如何实现线程间通信

    正常情况下,每个子线程完成各自的任务就可以结束了.不过有的时候,我们希望多个线程协同工作来完成某个任务,这时就涉及到了线程间通信了. 本文涉及到的知识点:thread.join(), object.w ...

  2. 24.循环栅栏 CyclicBarrier

    import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; /** * ...

  3. 04.join与interrupt

    join加入 public class JoinDemo { public volatile static int i = 0; public static class AddThread exten ...

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

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

  5. Delphi UTF编码 UTF8Encode、UTF8Decode、URLEncode、URLDecode

    一.URL简介    URL是网页的地址,比如 http://www.cnblogs.com.Web 浏览器通过 URL 从 web 服务器请求页面.    由于URL字符串常常会包含非ASCII字符 ...

  6. git代码提交步骤

    常用的步骤: 1)假如本地想关联git仓库,那么先git  init,git remote add origin [git地址] 2)假如是想直接从git仓库拉下来,那么git clone [git地 ...

  7. css 布局(圣杯、双飞翼)

    一. 圣杯布局. 左右固宽,中间自适应 三列布局,中间宽度自适应,两边定宽: 中间部分要在浏览器中优先展示渲染: 具体步骤:1.设置基本样式2.圣杯布局是一种相对布局,首先设置父元素container ...

  8. ARMv8 内存管理架构.学习笔记

    http://blog.csdn.net/forever_2015/article/details/50285955 版权声明:未经博主允许不得转载,请尊重原创, 谢谢!   目 录 第1章 分级存储 ...

  9. CSS 设置鼠标显示形状

    CSS 设置鼠标显示形状 <style type="text/css"><!-- span {display:block;line-height:30px;mar ...

  10. Error configuring application listener of class org.springframework.web.context.

    1.java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor 缺少asm-3.3.jar 2.java.lang.NoClassDe ...