【HDU】5766 Filling【轮廓线dp+burnside引理】
来源:互联网 发布:如何不备案用域名访问 编辑:程序博客网 时间:2024/05/23 10:05
题目链接:Filling
轮廓线dp出整个的,一半的,1/4的,然后用burnside引理去重。
#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef pair < int , int > pii ;#define clr( a , x ) memset ( a , x , sizeof a )const int mod = 1e9 + 7 ;const LL v2 = 500000004 ;const LL v4 = 250000002 ;int dp[2][1 << 21] , n ;int ans[22] = { 0 , 1 , 2 , 2 , 12 , 84 , 1641 , 50788 , 3183091 , 338785462 , 429880385 , 948920428 , 392930107 , 842384602 , 36468923 , 534250025 , 693507546 , 311288183 , 320259213 , 232751393 , 866290697 };;void up ( int& x , int y ) { x += y ; if ( x >= mod ) x -= mod ;}void show ( int s ) { printf ( "s = " ) ; for ( int i = 0 ; i < n + 1 ; ++ i ) { printf ( "%d" , s >> i & 1 ) ; } puts ( "" ) ;}void solve () { if ( n == 1 ) { printf ( "%d\n" , 1 ) ; return ; } int cur = 0 ; int tot = 1 << n + 1 , x = 1 << n , y = ( 3 << n - 1 ) + 1 ; clr ( dp , 0 ) ; dp[cur][0] = 1 ; for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 0 ; j < n ; ++ j ) { cur ^= 1 ; clr ( dp[cur] , 0 ) ; for ( int s = 0 ; s < tot ; ++ s ) if ( dp[cur ^ 1][s] ) { if ( j && !( s & 3 ) && !( s & x ) ) up ( dp[cur][s >> 1 | y] , dp[cur ^ 1][s] ) ; up ( dp[cur][s >> 1] , dp[cur ^ 1][s] ) ; } } } int ans0 = 0 , ans180 = 0 , ans90 = 0 , ans90_2 = 0 ; for ( int s = 0 ; s < tot ; ++ s ) { up ( ans0 , dp[cur][s] ) ; } clr ( dp , 0 ) ; dp[cur][0] = 1 ; for ( int i = 1 ; i < n / 2 ; ++ i ) { for ( int j = 0 ; j < n ; ++ j ) { cur ^= 1 ; clr ( dp[cur] , 0 ) ; for ( int s = 0 ; s < tot ; ++ s ) if ( dp[cur ^ 1][s] ) { if ( j && !( s & 3 ) && !( s & x ) ) up ( dp[cur][s >> 1 | y] , dp[cur ^ 1][s] ) ; up ( dp[cur][s >> 1] , dp[cur ^ 1][s] ) ; } } } if ( n & 1 ) { for ( int j = 0 ; j < n ; ++ j ) { cur ^= 1 ; clr ( dp[cur] , 0 ) ; for ( int s = 0 ; s < tot ; ++ s ) if ( dp[cur ^ 1][s] ) { if ( j && !( s & 3 ) && !( s & x ) ) up ( dp[cur][s >> 1 | y] , dp[cur ^ 1][s] ) ; up ( dp[cur][s >> 1] , dp[cur ^ 1][s] ) ; } } } else { for ( int j = 0 ; j < n / 2 ; ++ j ) { cur ^= 1 ; clr ( dp[cur] , 0 ) ; for ( int s = 0 ; s < tot ; ++ s ) if ( dp[cur ^ 1][s] ) { if ( j && !( s & 3 ) && !( s & x ) ) up ( dp[cur][s >> 1 | y] , dp[cur ^ 1][s] ) ; up ( dp[cur][s >> 1] , dp[cur ^ 1][s] ) ; } } } for ( int s = 0 ; s < tot ; ++ s ) { int ok = 1 ; for ( int j = 1 ; j <= ( n + 1 ) / 2 ; ++ j ) { if ( ( s & ( 1 << j ) ) && ( s & ( 1 << n + 1 - j ) ) ) { ok = 0 ; break ; } } if ( ok ) { up ( ans180 , dp[cur][s] ) ; if ( n % 2 == 0 && !( s & ( 1 << n ) ) && !( s & 3 ) ) { up ( ans180 , dp[cur][s] ) ; } //if ( dp[cur][s] ) show ( s ) ; } } int m = ( n + 1 ) / 2 ; tot = 1 << m + 1 ; x = 1 << m ; y = 3 << ( m - 1 ) | 1 ; for ( int o = 0 ; o < 1 << m ; ++ o ) { if ( ( n & 1 ) && ( o & ( 1 << ( n / 2 ) ) ) ) continue ; for ( int s = 0 ; s < tot ; ++ s ) { dp[cur][s] = 0 ; } dp[cur][0] = 1 ; for ( int i = 1 ; i < n / 2 + 1 ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { cur ^= 1 ; for ( int s = 0 ; s < tot ; ++ s ) { dp[cur][s] = 0 ; } for ( int s = 0 ; s < tot ; ++ s ) if ( dp[cur ^ 1][s] ) { if ( j && !( s & 3 ) && !( s & x ) ) up ( dp[cur][s >> 1 | y] , dp[cur ^ 1][s] ) ; up ( dp[cur][s >> 1] , dp[cur ^ 1][s] ) ; } } for ( int s = 0 ; s < tot ; ++ s ) { if ( ( s & 1 ) != ( ( o >> i - 1 ) & 1 ) ) dp[cur][s] = 0 ; } } for ( int s = 0 ; s < tot ; ++ s ) { int ok = 1 ; for ( int k = 0 ; k < m ; ++ k ) { if ( ( o >> k ) & ( s >> k + 1 ) ) { ok = 0 ; break ; } } if ( ok ) { up ( ans90 , dp[cur][s] ) ; if ( n % 2 == 0 && !( s & ( 1 << m ) ) && !( s & 1 ) ) { up ( ans90 , dp[cur][s] ) ; } } } } ans[n] = ( ( ans0 - ans180 + mod ) % mod * v4 + ( ans180 - ans90 + mod ) * v2 + ans90 ) % mod ; printf ( " , %d" , ans[n] ) ;}int main () { /* printf ( "{ 1" ) ; for ( n = 2 ; n <= 20 ; ++ n ) { solve () ; } printf ( " };\n" ) ; */ int T ; scanf ( "%d" , &T ) ; for ( int i = 1 ; i <= T ; ++ i ) { scanf ( "%d" , &n ) ; printf ( "Case #%d: %d\n" , i , ans[n] ) ; } return 0 ;}
0 0
- 【HDU】5766 Filling【轮廓线dp+burnside引理】
- hdu 4804 轮廓线dp
- HDU 4804 轮廓线DP
- HDU 4804 Campus Design 轮廓线DP
- hdu 4804 Campus Design 轮廓线dp
- HDU 4804 Campus Design 轮廓线DP
- HDU 4804 Campus Design 轮廓线DP
- [BZOJ1004][HNOI2008][Burnside引理][DP]Cards
- 【bzoj1004】[HNOI2008]Cards burnside引理+dp
- hdu 1693 Eat the Trees 轮廓线 插头dp
- hdu 4804 Campus Design (2013 南京 轮廓线dp)
- hdu 4804 Campus Design dp(记忆化搜索 /轮廓线 )
- HDU 1693 Eat the Trees(轮廓线DP)
- HDU 2167 Pebbles(轮廓线,状态压缩DP)
- poj2411 轮廓线dp
- 轮廓线dp初步
- POJ2144 轮廓线DP
- UVA11270 轮廓线DP
- asp.net 类自定义事件
- 前端面试的总结
- workaround for the python xlrd error
- Oracle 12c中添加scott用户的方法
- 文件路径的一些方法
- 【HDU】5766 Filling【轮廓线dp+burnside引理】
- javascript event(事件对象)详解
- php 深入理解addslashes函数
- ArrayList解析
- windows配置vpn服务端和客户端
- Java集合工具包简介
- JS基础——事件对象event
- HDU 1387 && UVa 540 Team Queue(队列应用)
- IDEA 热部署 update and resource