【BestCoder】 HDOJ 5171 GTY's birthday gift
来源:互联网 发布:四柱算命软件 编辑:程序博客网 时间:2024/05/22 01:32
矩阵快速幂。。。。构造矩阵的方法有很多种,任选一种即可。。。
#include <iostream>#include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 405#define maxm 400005#define eps 1e-7#define mod 10000007#define INF 999999999#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R#define pii pair<int, int>#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headLL mat[10][10];LL res[10][10];LL mid[10][10];int n, k;LL cal(int c){ memset(res, 0, sizeof res); memset(mat, 0, sizeof mat); res[1][1] = res[2][2] = res[3][3] = res[4][4] = 1; mat[1][1] = mat[1][2] = mat[2][1] = 1; mat[2][2] = 0; mat[1][3] = mat[1][4] = mat[2][3] = 1; mat[2][4] = 0; mat[3][3] = mat[4][4] = 1; while(c) { if(c % 2) { for(int i = 1; i <= 4; i++) for(int j = 1; j <= 4; j++) { LL t = 0; for(int k = 1; k <= 4; k++) t = (t + res[i][k] * mat[k][j]) % mod; mid[i][j] = t; } for(int i = 1; i <= 4; i++) for(int j = 1; j <= 4; j++) res[i][j] = mid[i][j]; } for(int i = 1; i <= 4; i++) for(int j = 1; j <= 4; j++) { LL t = 0; for(int k = 1; k <= 4; k++) t = (t + mat[i][k] * mat[k][j]) % mod; mid[i][j] = t; } for(int i = 1; i <= 4; i++) for(int j = 1; j <= 4; j++) mat[i][j] = mid[i][j]; c /= 2; } return res[1][4];}void work(){ LL a, b, x; scanf("%I64d%I64d", &a, &b); if(a < b) swap(a, b); LL res = (a + b) % mod; for(int i = 3; i <= n; i++) { scanf("%I64d", &x); if(x >= a) b = a, a = x; else b = max(b, x); res = (res + x) % mod; } res = (res + a * (cal(k + 1) - 1 + mod) % mod + b * cal(k) % mod) % mod; printf("%I64d\n", res);}int main(){ //for(int i = 1; i <= 10; i++) printf("AAAAA %lld\n", cal(i)); while(scanf("%d%d", &n, &k)!=EOF) { work(); } return 0;}
0 0
- 【BestCoder】 HDOJ 5171 GTY's birthday gift
- HDOJ-5171-GTY's birthday gift
- hdu 5171 GTY's birthday gift (BestCoder Round #29)
- hdu5171 GTY's birthday gift(BestCoder Round #29 1002)
- BestCoder Round#29 1002 GTY's birthday gift
- HDU 5171GTY's birthday gift
- HDU 5171 GTY's birthday gift
- HDU 5171 GTY's birthday gift
- hdu5171---GTY's birthday gift
- hdu5171 GTY's birthday gift
- HDU 5171 GTY's birthday gift (矩阵快速幂)
- HDU 5171 GTY's birthday gift 矩阵快速幂
- 【矩阵】HDU 5171 GTY's birthday gift 快速幂
- HDU 5171 GTY's birthday gift(矩阵快速幂)
- HDU 5171 GTY's birthday gift (矩阵快速幂)
- HDU 5171 GTY's birthday gift (矩阵快速幂)
- HDU - 5171 GTY's birthday gift (矩阵快速幂)
- hdu 5171 GTY's birthday gift(矩阵快速幂)
- JavaScript window.location对象
- 【BestCoder】 HDOJ 5170 GTY's math problem
- pthread_cond_timedwait的使用及疑问
- JavaScript window.location对象
- 菜鸟的Linux学习笔记之命令find
- 【BestCoder】 HDOJ 5171 GTY's birthday gift
- 字符数组,指针与数组,动态数组
- LeetCode OJ 之 Maximal Rectangle (最大的矩形)
- LINQ 流程简介
- 自定义ViewFlipper 实现滚动效果
- Maven 报错: Failure to transfer classworlds:classworlds:pom:1.1-alpha-2 from
- OpenCV Using Python——RGB颜色空间和YCbCr颜色空间的混合肤色检测
- Linux 内核学习(2)——内核配置与编译
- 新版本gem5 + dramsim2平台搭建