【HDU】5291 Candy Distribution 【DP+打标记】
2015-07-27 15:44
441 查看
传送门:【HDU】5291 Candy Distribution
my code:my~~code:
my code:my~~code:
[code]/************************************************************************* > 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] = 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] ) ; } int main () { int T ; scanf ( "%d" , &T ) ; for ( int i = 1 ; i <= T ; ++ i ) { solve () ; } return 0 ; }
相关文章推荐
- IOS开发—NSDateFormatter
- sqlplus的使用
- HDU 4336 Card Collector 概率DP 好题
- 《产品管理精华》目录
- patch补丁文件制作 使用和常见问题
- 【Struts2框架】第四节Struts标签-通用标签简述与常用标签大例子
- hdoj 1042 N!
- POJ 3087 Shuffle'm Up(模拟)
- SWF文件加密、混淆
- [知识点]计算几何I——基础知识与多边形面积
- 222题——Count Complete Tree Nodes(完全二叉树)
- 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
- xml与json 介绍
- 一个C语言编写的坦克大战游戏
- 解决Windows无法访问默认共享问题
- 阿里巴巴sku算法实现
- Extjs方法的构造
- Extjs方法的构造
- 线段树_POJ_3264
- 【HDU】5290 Bombing plan 【树形DP】