hdu 5389 Zero Escape dp
2015-08-14 21:26
316 查看
题意:n个数分成两堆,每堆的原根之和的原根分别要等于给出的AB,原根如:65536
是7,
6+5+5+3+6=25
然后2+5=7.
将其看成背包,则mod 9之后的那个值看成容量,做次背包就行了。
题目数据弱。。。
是7,
6+5+5+3+6=25
然后2+5=7.
将其看成背包,则mod 9之后的那个值看成容量,做次背包就行了。
//#include <bits/stdc++.h> #include <map> #include <set> #include <queue> #include <stack> #include <cmath> #include <time.h> #include <vector> #include <cstdio> #include <string> #include <iomanip> ///cout << fixed << setprecision(13) << (double) x << endl; #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 #define ls rt << 1 #define rs rt << 1 | 1 #define pi acos(-1.0) #define eps 1e-8 #define Mp(a, b) make_pair(a, b) #define asd puts("asdasdasdasdasdf"); #pragma comment(linker, "/STACK:102400000,102400000") typedef long long ll; typedef pair <int, int> pl; //typedef __int64 LL; const int inf = 0x3f3f3f3f; const int N = 100050; const ll mod = 258280327; ll dp [10]; int a ; int f( int x, int y ) { int tmp = x+y; tmp %= 9; return tmp ? tmp: 9; } int main() { int A, B, n; int tot; scanf("%d", &tot); while( tot-- ) { scanf("%d%d%d", &n, &A, &B); memset( dp, 0, sizeof( dp ) ); int sum = 0; for( int i = 1; i <= n; ++i ) { scanf("%d", &a[i]); sum = f( sum, a[i] ); } for( int i = 1; i <= n; ++i ) dp[i][a[i]] = 1; for( int i = 1; i <= n; ++i ) { for( int j = 0; j <= 9; ++j ) { dp[i][j] = ( dp[i][j] + dp[i-1][j] ) % mod; int k = f( a[i], j ); dp[i][k] = (dp[i][k] + dp[i-1][j]) % mod; } } ll ans = 0; if( f( A, B ) == sum ) ans = dp [A]; if( B == sum ) ans++; printf("%lld\n", ans); } return 0; }
题目数据弱。。。
相关文章推荐
- C++对象模型——对象复制语意学 (Object Copy Semantics)(第五章)
- 一步操作配置Word环境
- smartctl的使用
- hdu3306
- 总结python对csv文件的操作
- JUnit4测试框架
- 将博客搬至CSDN
- hdu5384 AC自动机模板题,统计模式串在给定串中出现的个数
- 翻转单词+左旋字符串
- 编程实现全排列
- spring自定义标签
- 时隔一周继续学习
- 支持RecyclerView的CursorAdapter的RecyclerViewCursorAdapter
- HDU1285确定比赛名次【拓扑排序】
- CentOS 7 编译64位Hadoop2.7.1
- [优化篇]OpenStack的Cinder后端存储技术——NFS
- 【转】php json_encode中文为空的解决办法
- 字符串连接(strcat)的函数
- Labeling Balls 3687(拓扑排序+反向建图)
- 默认函数实现全排列