【HDU】5291 Candy Distribution 【DP+打标记】
来源:互联网 发布:dw制作淘宝尺码表格 编辑:程序博客网 时间:2024/06/06 04:13
传送门:【HDU】5291 Candy Distribution
/************************************************************************* > File Name: D.cpp > Author: poursoul > Created Time: 2015年07月22日 星期三 13时04分24秒 ************************************************************************/#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef long long Int ;typedef pair < int , int > pi ;#define clr(a,x) memset ( a , x , sizeof a )const int MAXN = 100005 ;const int N = 50000 ;const int mod = 1e9 + 7 ;int dp[2][MAXN] ;int c1[MAXN] , c2[MAXN] ;int n ;void update ( int& x , int y ) { x += y ; while ( x >= mod ) x -= mod ; while ( x < 0 ) x += mod ;}void solve () { int x , cur = 0 , sum = 0 ; scanf ( "%d" , &n ) ; clr ( dp[cur] , 0 ) ; dp[cur][N] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { cur ^= 1 ; scanf ( "%d" , &x ) ; int L1 = N - sum - x , R1 = N + sum + x ; int L2 = N - sum , R2 = N + sum ; sum += x ; for ( int j = L1 - 2 ; j <= R1 + 10 ; ++ j ) { c1[j] = c2[j] = dp[cur][j] = 0 ; } for ( int j = L2 ; j <= R2 ; ++ j ) if ( dp[cur ^ 1][j] ) { int s = dp[cur ^ 1][j] ; if ( x % 2 == 0 ) { update ( c1[j - x] , s ) ; update ( c1[j + 2] , -s ) ; update ( c2[j + 1] , -s ) ; update ( c2[j + x + 3] , s ) ; } else { update ( c1[j - x] , s ) ; update ( c1[j + 1] , -s ) ; update ( c2[j + 2] , -s ) ; update ( c2[j + x + 3] , s ) ; } } for ( int j = L1 ; j <= R1 ; ++ j ) { update ( c1[j] , c1[j - 2] ) ; update ( c2[j] , c2[j - 2] ) ; } for ( int j = L1 ; j <= R1 ; ++ j ) { update ( c1[j] , c2[j] ) ; } for ( int j = L1 ; j <= R1 ; ++ j ) { dp[cur][j] = ( dp[cur][j - 1] + c1[j] ) % mod ; } } printf ( "%d\n" , dp[cur][N] ) ;}int main () { int T ; scanf ( "%d" , &T ) ; for ( int i = 1 ; i <= T ; ++ i ) { solve () ; } return 0 ;}
0 0
- 【HDU】5291 Candy Distribution 【DP+打标记】
- hdu 5291 Candy Distribution(dp)
- HDU 5291(Candy Distribution-差值dp)
- 【DP】HDOJ 5291 Candy Distribution
- 【多校第一场】【dp】 HDU 5291 Candy Distribution
- DP - hdu5291 Candy Distribution
- hdu 5291 Candy Distribution 2015 Multi-University Training Contest 1 树形dp,
- hdu 5291 Candy Distribution 2015 Multi-University Training Contest 1
- hdu 5291 Candy Distribution 2015 Multi-University Training Contest 1
- 2015多校第一场1004 hdu 5291 Candy Distribution
- Candy Distribution
- hdu 5502 Candy Game(dp)
- PKU 3327 Candy Distribution
- 3372 Candy Distribution
- POJ 3372 Candy Distribution
- poj 3372 Candy Distribution
- poj3372-Candy Distribution
- Poj 3372 Candy Distribution
- HDU 5312-Sequence(三角形数+推导)
- [Tue, 21 Jul 2015 ~ Mon, 27 Jul 2015] Deep Learning in arxiv
- Log日志记录buildMessage
- [****ViewController scrollViewDidScroll:]: message sent to deallocated instance 0x12d6c22f0
- tomcat结合nginx使用小结
- 【HDU】5291 Candy Distribution 【DP+打标记】
- Android小记:Camara录制视频的调用
- 51nod1050(最大子序列和)
- 百度地图,造成textview 成黑色方块
- 负载均衡原理与实践学习笔记(三)
- HTML中title前面小图标的实现
- mysql变量
- RHEL 6.5安装DRBD
- 插入排序