Sum of powers UVA
来源:互联网 发布:淘宝网上如何找货源 编辑:程序博客网 时间:2024/05/17 07:02
有一定难度的一道题目,具体的需要找出等式之间的关系,然后递推求解即可,推荐博客:点击打开链接,这里作者将需要用到的等式关系列举的很清楚了,然后递推求解就行了,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>#include<functional>using namespace std;const int N = 25;typedef long long LL;int C[N][N];LL res[N][N];LL m[N];LL getAbs(LL a){if (a < 0) return -a;return a;}int getSym(LL a){if (a < 0) return -1;else if(a>0) return 1;return 0;}LL gcd(LL a,LL b){if (b == 0) return a;return gcd(b, a%b);}void Reduct(LL& data,LL* arr,int n){LL d = gcd(data, getAbs(arr[0]));for (int i = 1; i <= n; i++){if (arr[i] == 0) continue;d = gcd(d,getAbs(arr[i]));}for (int i = 0; i <= n; i++)arr[i] = getAbs(arr[i])/d*getSym(arr[i]);data /= d;}void Cal(LL* aim,LL* source,LL mul,LL& basea,LL bases,int n){for (int i = 0; i <= n; i++){aim[i] = aim[i] * bases - source[i] * mul*basea;}basea *= bases;Reduct(basea, aim, n);}void Init(){C[0][0] = 1;for (int i = 1; i < N; i++){C[0][i] = C[i][i] = 1;for (int j = 1; j < i; j++)C[j][i] = C[j - 1][i - 1] + C[j][i - 1];}memset(m, 0, sizeof(m));memset(res, 0, sizeof(res));m[0] = 1;res[0][1] = 1;for (int i = 1; i <=20; i++){m[i] = 1;int n = i + 1;for (int j = 1; j <= n; j++){res[i][j] += C[j][n];}for (int j = 0; j < i; j++)Cal(res[i], res[j], C[j][n], m[i], m[j], n);m[i] *= C[i][n];Reduct(m[i], res[i], n);}}int main(){Init();int T;cin >> T;while (T--){int ind;cin >> ind;cout << m[ind];for (int i = ind+1; i >=0 ; i--)cout << " " << res[ind][i];cout << endl;if (T) cout << endl;}return 0;}
阅读全文
0 0
- Sum of powers UVA
- UVA 766 Sum of powers
- UVA 766 - Sum of powers(伯努利数)
- uva 766 - Sum of powers(数学+递推)
- PKU 1707 Sum of powers 解题报告
- [伯努利数] poj 1707 Sum of powers
- 【CF622F】The Sum of the k-th Powers (拉格朗日插值法)
- Game of Sum UVA
- uva 10891 Game of Sum
- UVA 10891 Game of Sum
- UVa 10891 Game of Sum
- Uva-10891-Game of Sum
- Uva 10891 Game of Sum
- Uva - 10891 - Game of Sum
- uva 10891 - Game of Sum
- uva 10891 game of sum
- UVA 10891 Game of Sum
- UVa 10891 - Game of Sum
- 大型网站购物车的实现
- mysql 5.7.20 解压版 配置安装
- 苏格拉底 《斐多篇》
- ES6入门第1章:关于ES6
- 静态方法与非静态方法的区别
- Sum of powers UVA
- MFC常见问题解惑
- 关于如何在Word PPT中使用LaTex数学公式
- 比特币源码解析(22)
- 深入理解闭包
- NGUI-2
- bug笔记
- 加法电路原理
- 如何通过SecureCRT转发功能实现外网访问内网服务