HDU 5117 Fluorescent (数学+状压DP)
题意:有 n 个灯,初始状态都是关闭,有m个开关,每个开关都控制若干个。问在m个开关按下与否的2^m的情况中,求每种情况下亮灯数量的立方和。
析:首先,如果直接做的话,时间复杂度无法接受,所以要对其进行小小的变形,设开灯数X,和每个开关的状态的对应关系是X = x1+x2+...+xn,其中 xi 可能为0,可能为1,那么要求的数X^3 = (x1+x2+...+xn) * (x1+x2+...+xn) * (x1+x2+...+xn) = ∑(xi*xj*xk),只有xi = xj = xk时,那么这种情况才会成立,所以对xi,xj,xk 进行枚举,dp[t][s] 表示前 t 个开关时,状态为s的可能数,这个状态 s 表示的是 xi,xj,xk的状态,只有s == 7 时,才满足条件。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 50 + 50;
const LL mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} LL dp[maxn][8];
LL st[maxn]; int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d %d", &n, &m);
for(int i = 1; i <= m; ++i){
st[i] = 0;
int x, y;
scanf("%d", &y);
for(int j = 0; j < y; ++j){
scanf("%d", &x);
st[i] |= 1LL<<x-1;
}
}
LL ans = 0;
FOR(i, 0, n) FOR(j, 0, n) FOR(k, 0, n){
ms(dp, 0); dp[0][0] = 1;
for(int t = 1; t <= m; ++t){
for(int s = 0; s < 8; ++s){
int newst = 0;
if(st[t]&1LL<<i) newst |= 1;
if(st[t]&1LL<<j) newst |= 2;
if(st[t]&1LL<<k) newst |= 4;
dp[t][s] = dp[t-1][s] + dp[t-1][s^newst];
}
}
ans = (ans + dp[m][7]) % mod;
}
printf("Case #%d: %I64d\n", kase, ans);
}
return 0;
}
HDU 5117 Fluorescent (数学+状压DP)的更多相关文章
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
- hdu 3681(bfs+二分+状压dp判断)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- hdu 4856 Tunnels (bfs + 状压dp)
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
- HDU 3362 Fix (状压DP)
题意:题目给出n(n <= 18)个点的二维坐标,并说明某些点是被固定了的,其余则没固定,要求添加一些边,使得还没被固定的点变成固定的, 要求总长度最短. 析:由于这个 n 最大才是18,比较小 ...
- HDU 3001 Travelling (状压DP,3进制)
题意: 给出n<=10个点,有m条边的无向图.问:可以从任意点出发,至多经过同一个点2次,遍历所有点的最小费用? 思路: 本题就是要卡你的内存,由于至多可经过同一个点2次,所以只能用3进制来表示 ...
随机推荐
- 首页大屏广告效果 jquery轮播图淡入淡出
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 02 - Unit06:弹出对话框
弹出对话框 如何实现弹出 //弹出出对话框 $("#can").load("alert/alert_notebook.html"); //显示背景色 $(&qu ...
- 黄聪:中国大陆的所有IP段,中国电信所有IP段、中国铁通所有IP段、中国网通所有IP段。
中国大陆的所有IP段,中国电信所有IP段.中国铁通所有IP段.中国网通所有IP段. 中国大陆的所有IP段: 47.153.128.0 47.154.255.25558.14.0.0 58.25.255 ...
- Fatal error: Call to undefined function Think\C() in /var/www/html/ceshi.hzheee.com/think/ThinkPHP/Library/Think/Think.class.php on line 334 这个问题解决
当APP_DEBUG为true时,包含图中这个文件,文件中又引导包含这些库文件,可以看出安装thinkphp3.2.3时ThinkPHP/Common/下是functions.php,把它改成func ...
- python mysql模块
多次使用python操作mysql数据库,先与大家分享一下,关于如何使用python操作mysql数据库.mysql并不是python自带的模块,因此需要下载安装.(在windows平台下介绍该使用过 ...
- 补充: istio安装
首先有一个概念: CRD - Custom Resource Definitions: CRDS文件: install/kubernetes/helm/istio/templates/crds.yml ...
- javascript的创建对象object.create()和属性检测hasOwnPrototype()和propertyIsEnumerable()
Object.create("参数1[,参数2]")是E5中提出的一种新的对象的创建方式. 第一个参数是要继承到新对象原型上的对象; 第二个参数是对象属性.这个参数可选,默认为fa ...
- 【UVA】10891 Game of Sum(区间dp)
题目 传送门:QWQ 分析 大力dp.用$ dp[i][j] $表示$ [i,j] $A能得到的最高分 我看到博弈论就怂... 代码 #include <bits/stdc++.h> us ...
- RPC框架之Thrift分析(转)
一.简介 1.Thrift是Facebook开发的跨语言的RPC服务框架.随后贡献给Apache开源组织.成为RPC服务的主流框架. 2.特点: 优点: 跨语言,支持java.c/c ...
- unicat,multicast,broadcast区别
单播.多播和广播单播”(Unicast).“多播”(Multicast)和“广播”(Broadcast)这三个术语都是用来描述网络节点之间通讯方式的术语.那么这些术语究竟是什么意思?区别何在? 1.单 ...