/** 第三题code */ #include <iostream> #include <string.h> using namespace std; typedef long long lld; const lld MAX_LEN = 1001; const lld MOD = 1000000007; class Matrix { public: Matrix(const Matrix &rhs) { memcpy(v, rhs.v, sizeof(v)); } Matrix() { memset(v, 0, sizeof(v)); } public: lld * operator[] (int index) { return v[index]; } lld * operator[] (int index) const { return (lld*)v[index]; } public: lld v[2][2]; }; Matrix operator *(const Matrix &lhs, const Matrix &rhs) { Matrix r; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { r[i][j] += lhs[i][k] * rhs[k][j]; r[i][j] %= MOD; } } } return r; } Matrix QuickPow(const Matrix &m, const lld n) { if (n == 1) { return m; } else if (n % 2 == 0) { const Matrix &tm = QuickPow(m, n >> 1); return tm * tm; } else { const Matrix &tm = QuickPow(m, n >> 1); return tm * tm *m; } } lld GetResult(const Matrix &m) { return ((m[1][0] * 3 + m[1][1] * 2) % MOD + MOD) % MOD; } int main() { Matrix m; m[0][0] = 3, m[0][1] = -1; m[1][0] = 1, m[1][1] = 0; int ic; cin >> ic; lld n; while (ic--) { cin >> n; if (n == 0) { cout << 1 << endl; continue; } cout << GetResult(QuickPow(m, n)) << endl; } } /** * 第二题code */ #include <iostream> #include <fstream> #include <string.h> using namespace std; typedef long long lld; lld MOD = 1000000007; lld dp[1001][1001]; void init(); //fstream r("1.in"); //fstream w("1.out"); int main() { init(); lld k; cin >> k; while (k--) { lld m, n; cin >> m >> n; cout << dp[m][n] << endl; } } void init() { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int r = 0; r <= 1000; ++r) { for (int c = 0; c <= r; ++c) { if (r > 0 && c > 0) { dp[r][c] = dp[r - 1][c - 1] + dp[r - 1][c]; } else if (r > 0) { dp[r][c] = dp[r - 1][c]; } dp[r][c] %= MOD; } } } /** 第一题code */ #include <iostream> using namespace std; int n; int m; int main() { cin >> m; while(m--) { cin >> n; if (n % 3) { cout << "lucky" << endl; }else { cout << "don't be discouraged" << endl; } } } 不要谢我,我是雷锋