hdu-5117 Fluorescent(状压dp)
题目链接:
Fluorescent
Time Limit: 3000/3000 MS (Java/Others)
Memory Limit: 512000/512000 K (Java/Others)
Initially, all the fluorescent lights are dark. For each switch, Matt will touch it with probability 1 .
As a curious gentleman, Matt wants to calculate E[X3], where X represents the number of bright lights at the end, E[X3] represents the expectation of cube of X.
For each test case, the first line contains N, M (1 ≤ N, M ≤ 50), denoting the number of fluorescent lights (numbered from 1 to N ) and the number of switches (numbered from 1 to M ).
M lines follow. The i-th line begins with an integer Ki (1 ≤ Ki ≤ N ). Ki distinct integers lij(1 ≤ lij ≤ N ) follow, denoting the fluorescent lights that the i-th switch controls.
E[X3] × 2M mod (109 + 7)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,m,a[51][51],k[50];
LL dp[51][8];
const LL mod=1e9+7;
LL solve(int u,int v,int w)
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=m;i++)
{
int tep=0;
for(int j=1;j<=k[i];j++)
{
if(a[i][j]==u)tep+=1;
if(a[i][j]==v)tep+=2;
if(a[i][j]==w)tep+=4;
}
for(int j=0;j<8;j++)dp[i][j]=dp[i-1][j];
for(int j=0;j<8;j++)dp[i][j^tep]+=dp[i-1][j],dp[i][j^tep]%=mod;
}
return dp[m][7]%mod;
}
int main()
{
int T,Case=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&k[i]);
for(int j=1;j<=k[i];j++)scanf("%d",&a[i][j]);
}
LL ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
ans=ans+solve(i,j,k),ans%=mod;
printf("Case #%d: %lld\n",++Case,ans);
}
return 0;
}
hdu-5117 Fluorescent(状压dp)的更多相关文章
- HDU - 5117 Fluorescent(状压dp+思维)
原题链接 题意 有N个灯和M个开关,每个开关控制着一些灯,如果按下某个开关,就会让对应的灯切换状态:问在每个开关按下与否的一共2^m情况下,每种状态下亮灯的个数的立方的和. 思路1.首先注意到N< ...
- HDU 4284Travel(状压DP)
HDU 4284 Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...
- HDU 4336 容斥原理 || 状压DP
状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...
- HDU 3001 Travelling ——状压DP
[题目分析] 赤裸裸的状压DP. 每个点可以经过两次,问经过所有点的最短路径. 然后写了一发四进制(真是好写) 然后就MLE了. 懒得写hash了. 改成三进制,顺利A掉,时间垫底. [代码] #in ...
- hdu 4114(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4114 思路:首先是floyd预处理出任意两点之间的最短距离.dp[state1][state2][u] ...
- HDU 3091 - Necklace - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 3811 Permutation 状压dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...
- HDU 5838 (状压DP+容斥)
Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...
- hdu 4628 Pieces 状压dp
题目链接 枚举所有状态, 1表示这个字符还在原来的串中, 0表示已经取出来了. 代码中j = (j+1)|i的用处是枚举所有包含i状态的状态. #include <iostream> #i ...
随机推荐
- ImageMagick来处理图片,缩放,调整高度等操作
单个缩放图片 convert 911.jpg -resize 25% 911.jpg 前面是要处理的图片路径,后面是输出的图片路径,我这么写就把原先图片缩放了 批量缩放图片 mogrify -samp ...
- maven项目打WAR包记录
打了个war包,各种不顺,也是以前没打过的原因,眼高手低了…… cmd 进入项目目录 打开 运行----cmd 进入命令窗口 键入 cd 回车 输入E\:mars\cdc 键入 mvn clean p ...
- 微信小程序学习笔记(4)--------框架之逻辑层
逻辑层 逻辑层(App Service):小程序框架的逻辑层是由JavaScript编写的,逻辑层将数据进行处理后发送给视图层,同时接受视图层的事件反馈. App进行程序注册,Page进行页面注册 g ...
- PL/SQL编程—视图
create or replace view test_view as select TestA.id, TestB.idno, TestB.name, TestB.sex from TestB le ...
- APDU指令返回码及其代表含义
9000 正常 成功执行6200 警告 信息未提供6281 警告 回送数据可能出错6282 警告 文件长度小于Le6283 警告 选中的文件无效6284 警告 FCI格式与P2指定的不符6300 警告 ...
- @@fetch_status
@@fetch_status是MicroSoft SQL SERVER的一个全局变量 其值有以下三种,分别表示三种不同含义:[返回类型integer] 0 FETCH 语句成功 -1 FETCH 语句 ...
- HTML5相册浏览插件
在线演示 本地下载
- 智能指针 auto_ptr、scoped_ptr、shared_ptr、weak_ptr
什么是RAII? RAII是Resource Acquisition Is Initialization的简称,是C++语言的一种管理资源.避免泄漏的惯用法. RAII又叫做资源分配即初始化,即:定义 ...
- Python 中lambda 简单介绍
转自:https://www.cnblogs.com/AlwaysWIN/p/6202320.html 在学习python的过程中,lambda的语法经常出现,现在将它整理一下,以备日后查看. 1.l ...
- SpringBoot中使用hikariCP
本篇文章主要实现SpringBoot中使用hikariCP: 一 .使用工具 1. JDK1.8 2. springToolSuit(STS) 3. maven 二.创建项目 1.首先创建一个Spri ...