题目大意:有n个灯泡,m个按钮,(1 <= n, m <= 50),每个按钮和ki 个灯泡相关, 按下后,转换这些灯泡的状态,问你所有2^m的按下按钮的

组合中亮着的灯泡的数量的三次方的和。

思路:要是将所有灯泡混在一起算很难算,我们先考虑  所有2^m的按下按钮的 组合中亮着的灯泡的数量的和, 我们可以枚举每个灯泡然后,计算出

有多少中情况这个灯泡是亮着的,然后全部求和。

现在是三次方的和,所以要变形一下, 我们设xi 为第i 个灯泡的状态(1开, 0关)那么对于每一种情况我们求的是

(x1 + x2 + x3 + ... + xn) * (x1 + x2 + x3 + ... + xn) * (x1 + x2 + x3 + ... + xn) = sigma(xi * xj * xk),然后枚举i,j,k用dp进行计算。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = + ;
const int M = 1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +;
const double eps=1e-;
const double pi=acos(-); int n, m;
int dp[N][];
bool Map[N][N]; void add(int &a, LL b) {
a += b; if(a >= mod) a -= mod;
}
int cal(int a, int b, int c) { memset(dp, , sizeof(dp));
dp[][] = ; for(int i = ; i <= m; i++) {
int state = ;
if(Map[i][a]) state |= ;
if(Map[i][b]) state |= ;
if(Map[i][c]) state |= ;
for(int s = ; s < ; s++) {
add(dp[i][s], dp[i - ][s]);
add(dp[i][s], dp[i - ][s ^ state]);
}
} return dp[m][];
}
int main() {
int T; scanf("%d", &T);
for(int cas = ; cas <= T; cas++) {
memset(Map, false, sizeof(Map));
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++) {
int k; scanf("%d", &k);
while(k--) {
int x; scanf("%d", &x);
Map[i][x] = true;
} } int ans = ; for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
for(int k = ; k <= n; k++) {
add(ans, cal(i, j, k));
}
}
} printf("Case #%d: %d\n", cas, ans);
}
return ;
} /*
*/

hdu 5117 数学公式展开 + dp的更多相关文章

  1. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  2. hdu 2296 aC自动机+dp(得到价值最大的字符串)

    Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  4. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  5. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  6. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  7. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  8. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  9. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

随机推荐

  1. opencv学习---打开摄像头检测个人头像

    opencv中具有检测人体各部分的级联分类器,在opencv文件夹里面的sources/data/haarcascades里面. 这里要选择的是能够检测人体头像的还有检测眼睛的级联分类器的文件. 它们 ...

  2. 管理页面的 setTimeout & setInterval

    在管理 setTimeout & setInterval 这两个 APIs 时,笔者通常会在顶级(全局)作用域创建一个叫 timer 的对象,在它下面有两个数组成员 —— {sto, siv} ...

  3. jQuery图表插件Flot中文文档

    转载自:http://www.itivy.com/ivy/archive/2011/6/4/jquery-flot-chinese-doc.html 最近正在使用JQuery的flot进行画图,但是这 ...

  4. spring和Quartz的集群(二)

    一:前沿 写完了这两篇才突然想起来,忘记了最关键的东西,那就是在配置文件这里的配置,还有数据库的配置.这是郁闷啊!继续吧! 二:内容配置 我们在集成的时候需要自己配置一个quartz.properti ...

  5. 洛谷 3029 [USACO11NOV]牛的阵容Cow Lineup

    https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer t ...

  6. Hexo&Github-Pages搭建个人博客

    some基础知识 hexo hexo是一款基于Node.js的静态博客框架 github-pages说明 github有两种主页,一种是github-page(个人主页),一种是项目主页,本教程针对个 ...

  7. linux 执行shell脚本的4种方法总结

    bash shell 脚本的方法有多种,假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在的目录(此时, ...

  8. ZOJ3229 Shoot the Bullet [未AC]

    Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge Gensokyo is a world which exist ...

  9. Mayor's posters(线段树+离散化+区间染色)

    题目链接:http://poj.org/problem?id=2528 题目: 题意:将n个区间进行染色(对于同一个区间,后一次染色会覆盖上一次的染色),问最后可见的颜色有多少种. 思路:由于区间长度 ...

  10. Python switch-case语句的实现 -- 字典模拟实现

    static void print_asru_status(int status, char *label) { char *msg = NULL; switch (status) { : msg = ...