dp(i, s)表示考虑了前i个数后, 能取到的数的集合为s时的方案数.对于1~min(L, K)枚举更新, 剩下的直接乘就好了. 复杂度O(T*K*2^N)。。。好像有点大, 但是可以AC。。。。

------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define b(i) (1 << (i))
const int MOD = 1000000007;
int N, g, L, dp[b(21)];
inline void upd(int &x, int t) {
if((x += t) >= MOD) x -= MOD;
}
int main() {
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &N, &g, &L);
memset(dp, 0, sizeof dp);
dp[1] = 1;
int All = b(g + 1) - 1;
while(N--) {
for(int s = All; s; s--) if(dp[s]) {
int t = dp[s];
for(int i = min(g, L); i; i--)
upd(dp[s | ((s << i) & All) | b(i)], t);
if(L > g) upd(dp[s], ll(t) * (L - g) % MOD);
}
}
int ans = 0;
for(int i = All; i; i--)
if(i & b(g)) upd(ans, dp[i]);
printf("%d\n", ans);
}
return 0;
}

------------------------------------------------------------------------------

3870: Our happy ending

Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 146  Solved: 84
[Submit][Status][Discuss]

Description

There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.
Y*wan still remember the day he first meets the devil. Now everything is done and the devil is gone. Y*wan feel very sad and suicide.
You feel guilty after killing so many loli, so you suicide too.
Nobody survive in this silly story, but there is still some hope, because this is just a silly background story during one programming contest!
And the last problem is:
Given a sequence a_1,a_2,...,a_n, if we can take some of them(each a_i can only be used once), and they sum to k, then we say this sequence is a good sequence.
How many good sequence are there? Given that each a_i is an integer and 0<= a_i <= L.
You should output the result modulo 10^9+7.

Input

The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains 3 integers n, k, L.
T<=20, n,k<=20 , 0<=L<=10^9.

Output

For each cases, output the answer in a single line.

Sample Input

1
2 2 2

Sample Output

6

HINT

Source

By WJMZBMR

转载于:https://www.cnblogs.com/JSZX11556/p/5175910.html

BZOJ 3870: Our happy ending( 状压dp )相关推荐

  1. BZOJ.3058.四叶草魔杖(Kruskal 状压DP)

    题目链接 \(2^{16}=65536\),可以想到状压DP.但是又有\(\sum A_i\neq 0\)的问题.. 但是\(2^n\)这么小,完全可以枚举所有子集找到\(\sum A_i=0\)的, ...

  2. our happy ending(状压dp)

    题意:给定一个n,k,l. 问有多少长度为n的序列满足选出一些数使得他们相加为k,数列中每个数都在1-l以内. Solution 正解还是很妙的. 状压dp,设dp[i][j]表示长度为i的序列,能表 ...

  3. bzoj 3055礼物运送 floyed + 状压DP

    bzoj 3055: 礼物运送 floyed first 设f[i][S]表示取到了S集合中的所有点(不一定是经过的所有点),最后停在了i的最优值. 初始就f[i][{i}] = dis[1][i] ...

  4. bzoj 2560: 串珠子【状压dp】

    正难则反,设g[s]为集合s不一定联通的方案数,这个很好求,把边数+1乘起来即可,f[s]为s一定联通的方案数 f考虑容斥,就是g[s]-Σf[nw]*g[s^nw],nw是s的子集,这样就减掉了不联 ...

  5. 【bzoj 2073】PRZ(状压DP)

    传送门biu~ 把当前过去了哪些人进行状态压缩,枚举当前状态走的最后一批人来转移. #include<bits/stdc++.h> #define inf 0x3f3f3f3f #defi ...

  6. BZOJ 4042 Luogu P4757 [CERC2014]Parades (树形DP、状压DP)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=4042 (Luogu) https://www.luogu.org/prob ...

  7. BZOJ 2073: [POI2004]PRZ( 状压dp )

    早上这道题没调完就去玩NOI网络同步赛了.... 状压dp , dp( s ) 表示 s 状态下所用的最短时间 , 转移就直接暴力枚举子集 . 可以先预处理出每个状态下的重量和时间的信息 . 复杂度是 ...

  8. 【BZOJ】1076 [SCOI2008]奖励关 期望DP+状压DP

    [题意]n种宝物,k关游戏,每关游戏给出一种宝物,可捡可不捡.每种宝物有一个价值(有负数).每个宝物有前提宝物列表,必须在前面的关卡取得列表宝物才能捡起这个宝物,求期望收益.k<=100,n&l ...

  9. BZOJ 2734 [HNOI2012]集合选数 (状压DP、时间复杂度分析)

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2734 题解 嗯早就想写的题,昨天因为某些不可告人的原因(大雾)把这题写了,今天再来写题解 ...

最新文章

  1. 分布式缓存灵魂十连,你能坚持几个?
  2. windows 10 python哪个版本的好-windows10 conda python多版本切换
  3. xshell 安装yum_本地yum源配置及Xshell连接
  4. 02_c3p0之c3p0-config.xml配置案例,操作c3p0的jdbcUtil工具类的编写
  5. MyBatis教程– CRUD操作和映射关系–第1部分
  6. 【Qt开发经验】Qt信号槽连接不成功问题原因汇总
  7. python getostime_python转换在os.utime中使用的datetime
  8. java 泛型 类型形参(Type Parameters)Type Parameters 边界(Bound) 类型
  9. 关于Java 8 forEach
  10. texshop 使用技巧
  11. 《规划力:如何清晰预见成功轨迹》PDF文字版电子书下载
  12. 勒索病毒“WannaCry”之复现过程(永恒之蓝)
  13. SIM800C 不停的回复Call Ready NET指示灯一直不能进入3秒闪烁的状态
  14. 使用 IDEA 文件统计工具 Statistic
  15. 游戏私服频繁被DDOS攻击怎么办
  16. 如何成为牛逼的程序员
  17. 项目无法识别 ?. 语法,导致报错Module parse failed: Unexpected token
  18. java+vue实现词云生成+展示(kumo+echarts-wordcloud )
  19. 不同vlan间的通信--三层交换技术
  20. 面试笔试杂项积累-leetcode 6-10

热门文章

  1. MorGain2020中文版
  2. 【消息中间件】Spring整合RabbitMQ
  3. margin的塌陷现象
  4. Linux 升级 Python 至 3.x
  5. 一、Cocos2dx在visualStudio或者vc++中环境搭建(入门篇)
  6. QTime使用中遇到的”not enough actual parameters for macro 'min'“问题
  7. iOS:Tools:快速注释Doxygen
  8. JDK8之Stream
  9. 使用 Navicat Lite 连接 Oracle 数据库
  10. 微软发话:Win10杀毒软件要优先选它