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

#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的几种定时器

    https://blog.csdn.net/coolwindd/article/details/82804189 1.@Scheduled注解 @Scheduled注解是最简单的方式,只需要启用定时器 ...

  2. win10下安装Ubuntu后,启动时没有win10选项解决方法

    通过在ubuntu里修改启动引导,解决. 1.进入Ubuntu系统,Ctrl+alt+t进入终端,输入以下命令即可 sudo gedit /etc/default/grub 2.在打开的gedit编辑 ...

  3. 笔记72 高级SSM整合

    遇到的问题: 1.进行spring mvc测试的时候报错 测试代码: package com.li.test; import com.github.pagehelper.PageInfo; impor ...

  4. Vue学习笔记【33】——相关文章

    vue.js 1.x 文档 vue.js 2.x 文档 String.prototype.padStart(maxLength, fillString) js 里面的键盘事件对应的键码 Vue.js双 ...

  5. html2canvas截图白边显示问题

    html2canvas(document.getElementById('resource_chart'),{ useCORS:true, logging:false, width:$('#resou ...

  6. [CSP-S模拟测试]:金(king)(高精度+模拟)

    题目传送门(内部题36) 输入格式 第一行一个整数$T$,表示数据组数. 接下来$T$行,每行两个空格隔开的整数$n,m$. 输出格式 对于每组数据,输出一行$"Yes"$或$&q ...

  7. (转)图文详解MyEclipse中新建Maven webapp项目的步骤

    转:https://blog.csdn.net/ClementAD/article/details/46592557 MyEclipse中创建新的Maven项目(webapp目录结构)过程如下:   ...

  8. ARM系列处理器的分类

    1.ARM ARM即以英国ARM(Advanced RISC Machines)公司的内核芯片作为CPU,同时附加其他外围功能的嵌入式开发板,用以评估内核芯片的功能和研发各科技类企业的产品. ARM ...

  9. PHP 工程师技能图谱

    # PHP 工程师技能图谱## 基础知识 - HTTP - HEADER - REQUEST - RESPONSE - GET/POST/PUT/DELETE/PATCH/CONNECT/OPTION ...

  10. 百度上有个最难数独, 用python跑它

    直接上代码 #!/usr/bin/python3 #coding=GB2312 import tkinter as tk import threading import time import ran ...