2015 questions in group B in 9th, group B in 2015

Source: Internet
Author: User

2015 questions in group B in 9th, group B in 2015

// 10e9 can only be a Matrix Recursion !!!! // Matrix Recursion + binary power # include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <vector> # include <algorithm> # include <cmath> using namespace std; typedef long LL; const int Mod = 1000000007; struct Matrix {LL a [6] [6]; Matrix (int x) {memset (a, 0, sizeof (a); for (int I = 0; I <6; I ++) a [I] [I] = x ;} matrix operator * (const Matrix & B) const {Matrix c (0); for (int I = 0; I <6; I ++) for (int j = 0; j <6; j ++) for (int k = 0; k <6; k ++) {c. a [I] [j] + = (a [I] [k] * B. a [k] [j]) % Mod; c. a [I] [j] % = Mod;} return c ;}}; Matrix fast_mod (Matrix x, int r) {Matrix ret (1); while (r) {if (r & 1) ret = ret * x; x = x * x; r >>= 1;} return ret;} int main () {Matrix st (0); for (int I = 0; I <6; I ++) for (int j = 0; j <6; j ++) st. a [I] [j] = 4; int n, m; cin> n> m; for (int I = 0; I <m; I ++) {int u, v; cin> u> v; st. a [U-1] [V-1] = 0; st. a [V-1] [U-1] = 0;} Matrix ret = fast_mod (st, n-1); LL ans = 0; for (int I = 0; I <6; I ++) for (int j = 0; j <6; j ++) {ans + = (4 * ret. a [I] [j]) % Mod; ans % = Mod;} cout <ans <endl; return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.