Codeforces 1185G2 Playlist for Polycarp (hard version) 背包,暴力
题意及思路:https://www.cnblogs.com/Als123/p/11061147.html
代码:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define db double
#define pii pair<int, int>
using namespace std;
const LL mod = 1e9 + 7;
LL mul(LL x, LL y) {
return ((LL)x * y) % mod;
}
LL add(LL x, LL y) {
return ((LL)x + y) % mod;
}
LL dp[55][55][55][3], sum[55][55][55], ssum[3];
LL f[3][55][2505], jc[55], f1[55][55][2505];
vector<int> a[3];
int n, m;
LL ans = 0;
void init(int x) {
jc[0] = 1;
for (int i = 1; i <= x; i++) {
jc[i] = mul(jc[i - 1], i);
}
dp[1][0][0][0] = dp[0][1][0][1] = dp[0][0][1][2] = 1;
for (int i = 0; i <= x; i++)
for (int j = 0; j <= x; j++)
for (int k = 0; k <= x; k++) {
for (int t = 0; t < 3; t++) {
if(t != 0) dp[i + 1][j][k][0] += dp[i][j][k][t];
if(t != 1) dp[i][j + 1][k][1] += dp[i][j][k][t];
if(t != 2) dp[i][j][k + 1][2] += dp[i][j][k][t];
}
sum[i][j][k] = mul(mul(jc[i], mul(jc[j], jc[k])), add(add(dp[i][j][k][0], dp[i][j][k][1]), dp[i][j][k][2]));
}
}
void init1() {
for (int flag = 0; flag < 3; flag++) {
f[flag][0][0] = 1;
for (int i = 0; i < a[flag].size(); i++)
for (int j = i + 1; j >= 1; j--)
for (int k = ssum[flag]; k >= a[flag][i]; k--)
f[flag][j][k] = add(f[flag][j][k], f[flag][j - 1][k - a[flag][i]]);
}
for (int i = 0; i <= a[0].size(); i++)
for (int j = 0; j <= a[1].size(); j++)
for (int k = 0; k <= ssum[0]; k++) {
for (int t = 0; t <= ssum[1]; t++) {
f1[i][j][k + t] = add(f1[i][j][k + t], mul(f[0][i][k], f[1][j][t]));
}
}
}
void solve() {
for (int i = 0; i <= a[2].size(); i++)
for (int j = 0; j <= a[0].size(); j++)
for (int k = 0; k <= a[1].size(); k++) {
for (int t = 0; t <= ssum[2]; t++) {
int tmp1 = m - t;
ans = add(ans, mul(sum[j][k][i], mul(f1[j][k][tmp1], f[2][i][t])));
}
}
printf("%lld\n", ans);
}
int main() {
int t, x;
init(50);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &t, &x);
a[x - 1].push_back(t);
ssum[x - 1] += t;
}
if(a[0].size() > a[2].size()) {
swap(a[0], a[2]);
swap(ssum[0], ssum[2]);
}
if(a[1].size() > a[2].size()) {
swap(a[1], a[2]);
swap(ssum[1], ssum[2]);
}
init1();
solve();
}
Codeforces 1185G2 Playlist for Polycarp (hard version) 背包,暴力的更多相关文章
- Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)
题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...
- Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)
因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
- CodeForces - 632E Thief in a Shop 完全背包
632E:http://codeforces.com/problemset/problem/632/E 参考:https://blog.csdn.net/qq_21057881/article/det ...
- Codeforces A. Playlist(暴力剪枝)
题目描述: Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 1442D - Sum(找性质+分治+背包)
Codeforces 题面传送门 & 洛谷题面传送门 智商掉线/ll 本来以为是个奇怪的反悔贪心,然后便一直往反悔贪心的方向想就没想出来,看了题解才发现是个 nb 结论题. Conclusio ...
- Codeforces Round #383 (Div. 2) D 分组背包
给出一群女孩的重量和颜值 和她们的朋友关系 现在有一个舞台 ab是朋友 bc是朋友 ac就是朋友 给出最大承重 可以邀请这些女孩来玩 对于每一个朋友团体 全邀请or邀请一个or不邀请 问能邀请的女孩的 ...
- Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...
- Codeforces 1077F2 Pictures with Kittens (hard version)(DP+单调队列优化)
题目链接:Pictures with Kittens (hard version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:数据量5000, ...
随机推荐
- Ubuntu 服务器Webmin错误的解决
一:This web server is running in SSL mode. Try the URL https://***********:10000/ instead. 解决方案: 1.ss ...
- Vue--事件处理(逐个学习事件修饰符)
.capture .self .once 主要学习这三个事件修饰符的用法先来看看capture capture即是给元素添加一个监听器,当元素发生冒泡时,先触发带有该修饰符的元素.若有多个该修饰符,则 ...
- ltp-ddt nand_mtd_dd_rw_jffs2
error: 由于在uboot下没有发现坏块,将核心代码剥离出来调试: flash_eraseall -q -j /dev/mtd1mkdir -p /mnt/partition_nand_1419m ...
- ltp-ddt smp_cpu_affinity
# @name SMP CPU Affinity# @desc Check that processes assigned to multiple CPUs complete without erro ...
- JVM参数说明
转载于https://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html文章 JVM参数说明 -Xms:初始堆大小 默认值=物理内存的1 ...
- sql查询时间范围
select * from table where Time>='2019-05-09 00:05:36' and Time<='2019-05-10 00:05:36'
- Python repr, str, eval 使用小记 及 str 和 repr的区别
>>> s = '1+2'>>> x = eval(s) #把引号剥离一次,就变成了运算1+2>>> x3>>> ss = st ...
- springmvc中拦截器配置格式
对于springmvc,有两种方式配置拦截器. 一是实现HandlerInterceptor接口,如 public class MyInterceptor1 implements HandlerInt ...
- Bootstrap的本地引入
今天用前端框架时选择了Bootstrap,然后东西都下好了本地就是引入不进去. 查了一下发现必须jquery要在BootStrap之前引入,然后我更改了引入顺序,发现还是不行 <script s ...
- mybatis整合redis二级缓存
mybatis默认开启了二级缓存功能,在mybatis主配置文件中,将cacheEnabled设置成false,则会关闭二级缓存功能 <settings> <!--二级缓存默认开启, ...