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

#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. 三、IIS通过目录方式部署以供外部调试

    一.IIS 下面是通过 gif 为 因项目是bin生成后的,非运行方式的调试,所以断点调试无效,仅修改文件后,右击项目重新生成解决方案即可,好处:启动快,坏处:不可以断点调试查看变量和分步执行语句.

  2. Razor 保存动态表格

    本文转载自  ASP.NET MVC数组模型绑定 ,https://www.cnblogs.com/choon/p/5429065.html 内容根据评论内容中的方式有所调整 在ASP.NET MVC ...

  3. Linux 下安装sql server 时 2G内存限制的最新(2019-08-15) 解决方案

    关于 sqlserver 在linux下安装时有最小内存限制的问题,网上有很多类似的说明,那些操作都是正确的,如果不成功可能 “姿势”不对. 需要注意的是:不能使用最新版本!!!  不能在线下载!!! ...

  4. @PathVariable、@RequestParam、@RequestBody注解

    讲解更加详细的参考资料 https://blog.csdn.net/u011410529/article/details/66974974 https://www.cnblogs.com/soul-w ...

  5. Elasticsearch index

    POST/{index}/{type} Elasticsearch自动生成ID,自动生成的 ID 是 URL-safe. 基于 Base64 编码且长度为20个字符的 GUID 字符串. 这些 GUI ...

  6. Inno Setup Conpiler 使用方法

    Inno Setup Conpiler 使用方法: 首先创建一个空白的脚本文件,点击NEXT 然后会进入到这个界面,提示你详细说明一下软件的基本信息 Application name: 应用程序名称 ...

  7. FastDFSClient上传图片工具类

    package cn.lijun.core.util; import org.apache.commons.io.FilenameUtils;import org.csource.common.Nam ...

  8. shell变量,字符串,数组

    一.shell变量定义: 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头: 中间不能有空格,可以使用下划线: 不能使用标点符号: 不能使用bash里的关键字. 变量使用: 使用一个定义过的 ...

  9. Codeforces #55D (数位dp+离散化)

    Description Volodya is an odd boy and his taste is strange as well. It seems to him that a positive ...

  10. 数组转xls格式的excel文件&数据转csv格式的excle

    /** * 数组转xls格式的excel文件 * @param array $data 需要生成excel文件的数组 * @param string $filename 生成的excel文件名 * 示 ...