BZOJ 1089 SCOI 2003 严格n元树 递推+高精度
2014-10-28 17:43
302 查看
题目大意:严格n元树的定义是所有的点都有n个儿子节点或者没有儿子节点。问m层的严格n元树的个数是多少。
思路:递推式十分简单,这题主要是再考高精度。
递推式S[i] = S[i - 1] ^P + 1,ans = S[i] - S[i - 1]。
高精度的话这个题用的还是挺多的,有+-*^还有输出,写的很爽
CODE:
思路:递推式十分简单,这题主要是再考高精度。
递推式S[i] = S[i - 1] ^P + 1,ans = S[i] - S[i - 1]。
高精度的话这个题用的还是挺多的,有+-*^还有输出,写的很爽
CODE:
#include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define BASE 1000 #define MAX 1010 using namespace std; struct BigInt{ int num[MAX],len; BigInt(int _ = 0) { memset(num,0,sizeof(num)); if(_) { num[1] = _; len = 1; } else len = 0; } BigInt operator +(const BigInt &a)const { BigInt re; re.len = max(len,a.len); int temp = 0; for(int i = 1; i <= re.len; ++i) { re.num[i] = num[i] + a.num[i] + temp; temp = re.num[i] / BASE; re.num[i] %= BASE; } if(temp) re.num[++re.len] = temp; return re; } BigInt operator -(const BigInt &a)const { BigInt re = *this; for(int i = 1; i <= len; ++i) { re.num[i] -= a.num[i]; if(re.num[i] < 0) re.num[i] += BASE,--re.num[i + 1]; if(re.num[i]) re.len = i; } return re; } BigInt operator *(const BigInt &a)const { BigInt re; for(int i = 1; i <= len; ++i) for(int j = 1; j <= a.len; ++j) { re.num[i + j - 1] += num[i] * a.num[j]; re.num[i + j] += re.num[i + j - 1] / BASE; re.num[i + j - 1] %= BASE; } re.len = len + a.len; if(!re.num[re.len]) --re.len; return re; } void operator *= (const BigInt &a) { *this = *this * a; } BigInt operator ^(int a)const { BigInt re(1); for(int i = 1; i <= a; ++i) re *= *this; return re; } }s[50]; ostream &operator <<(ostream &os,const BigInt &a) { os << a.num[a.len]; for(int i = a.len - 1; i; --i) os << fixed << setfill('0') << setw(3) << a.num[i]; return os; } int n,p; int main() { cin >> n >> p; s[0] = BigInt(1); for(int i = 1; i <= p; ++i) s[i] = (s[i - 1] ^ n) + BigInt(1); BigInt ans = s[p] - s[p - 1]; cout << ans << endl; return 0; }
相关文章推荐
- 【BZOJ1089】[SCOI2003]严格n元树【递推】【高精度】
- [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
- BZOJ 1089: [SCOI2003]严格n元树 递推 高精度
- [BZOJ1089][SCOI2003][递推][高精度]严格n元树
- BZOJ 1089: [SCOI2003]严格n元树 递推,高精度
- 【BZOJ】1089: [SCOI2003]严格n元树(递推+高精度/fft)
- [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
- bzoj 1089 [SCOI2003]严格n元树(DP+高精度)
- bzoj 1089 [SCOI2003]严格n元树(DP+高精度)
- bzoj1089: [SCOI2003]严格n元树(高精度)
- BZOJ 1089 SCOI2003 严格n元树 动态规划+高精度
- BZOJ 1089: [SCOI2003]严格n元树(dp+高精度快速幂)
- 简单高精度模板(bzoj 1089: [SCOI2003]严格n元树)
- [BZOJ 1089][SCOI2003]严格n元树:DP+高精度
- [BZOJ]1089: [SCOI2003]严格n元树 DP+高精度
- bzoj 1089: [SCOI2003]严格n元树 (dp+高精度)
- [BZOJ1089][SCOI2003]严格n元树(dp+数学相关+高精度)
- BZOJ1089: [SCOI2003]严格n元树
- 【SCOI2003】【BZOJ1089】严格n元树
- bzoj1089 [SCOI2003]严格n元树(dp+高精)