题目链接

传送门

简单数学题

题目

思路

前置知识:
\[ \sum_{i=m}^{n}C_{i}^{m}=C_{n+1}^{m+1} \]
此题化简:
\[ \begin{aligned} &\sum_{i=1}^{n}i\sum_{j=i}^{n}C_{j}^{i}& \\ =&\sum_{i=1}^{n}iC_{n+1}^{i+1}& \\ =&(n+1)\sum_{i=1}^{n}C_{n}^{i}-\sum_{i=1}^{n}C_{n+1}^{i+1}&\\ =&(n+1)(2^n-1)-(2^{n+1}-C_{n+1}^{0}-C_{n+1}^{1})&\\ =&(n-1)2^{n}+1 \end{aligned} \]

代码实现如下:

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;LL n;LL qpow(LL x, LL n) {LL res = 1;while(n) {if(n & 1) res = res * x % mod;x = x * x % mod;n >>= 1;}return res;
}int main() {while(~scanf("%lld", &n)) {printf("%lld\n", ((n - 1) % mod * qpow(2, n) % mod + 1) % mod);}return 0;
}

Count

题目

思路

我们假设第n头牛的编号为\(f_{n}\),由题意可知递推式为\(f_{n}=f_{n-1}+2 \times f_{n-2}+n^{3}\),根据这个我们可以推得矩阵快速幂的系数矩阵为:
\[ \left\{ \begin{matrix} 1 & 1 & 0 & 0 & 0 & 0 \\ 2 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 1 & 0 & 0 & 0 \\ 3 & 0 & 3 & 1 & 0 & 0 \\ 3 & 0 & 3 & 2 & 1 & 0 \\ 1 & 0 & 1 & 1 & 1 & 1 \end{matrix} \right\} \]

代码实现如下

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)const double eps = 1e-8;
const int mod = 123456789;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;int t;
LL n;
int f[10], a[10][10];void mulself(int a[10][10]) {int c[10][10];memset(c, 0, sizeof(c));for(int i = 0; i < 10; i++) {for(int j = 0; j < 10; j++) {for(int k = 0; k < 10; k++) {c[i][j] = (c[i][j] + (long long)a[i][k] * a[k][j]) % mod;}}}memcpy(a, c, sizeof(c));
}void mul(int f[10], int a[10][10]) {int c[10];memset(c, 0, sizeof(c));for(int i = 0; i < 10; i++) {for(int j = 0; j < 10; j++) {c[i] = (c[i] + (long long)f[j] * a[j][i] ) % mod;}}memcpy(f, c, sizeof(c));
}int main() {scanf("%d", &t);while(t--) {scanf("%lld", &n);f[0] = 2, f[1] = 1, f[2] = 8, f[3] = 4, f[4] = 2, f[5] = 1;a[0][0] = 1, a[0][1] = 1, a[0][2] = 0, a[0][3] = 0, a[0][4] = 0, a[0][5] = 0;a[1][0] = 2, a[1][1] = 0, a[1][2] = 0, a[1][3] = 0, a[1][4] = 0, a[1][5] = 0;a[2][0] = 1, a[2][1] = 0, a[2][2] = 1, a[2][3] = 0, a[2][4] = 0, a[2][5] = 0;a[3][0] = 3, a[3][1] = 0, a[3][2] = 3, a[3][3] = 1, a[3][4] = 0, a[3][5] = 0;a[4][0] = 3, a[4][1] = 0, a[4][2] = 3, a[4][3] = 2, a[4][4] = 1, a[4][5] = 0;a[5][0] = 1, a[5][1] = 0, a[5][2] = 1, a[5][3] = 1, a[5][4] = 1, a[5][5] = 1;if(n <= 2) {printf("%d\n", f[n]);continue;}n -= 2;while(n) {if(n & 1) mul(f, a);mulself(a);n >>= 1;}printf("%d\n", f[n]);}return 0;
}

转载于:https://www.cnblogs.com/Dillonh/p/11162507.html

字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛相关推荐

  1. “字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛 1,2,3,4,5,7,8,9,10

    1001: hzy 和zsl 的生存挑战 Problem Description zsl 和hzy 来到了臭臭城堡,打算挑战臭臭城堡的大魔王hyz,大魔王hyz设置了这样的一个挑战: zsl 和hzy ...

  2. 人类史上最大最好的希望事件 字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛

    作为CNCS的半壁江山,狗哥常常在宇宙中心邵阳眺望黄浦江,夜晚的星空总是迷人,有时候还能见到彗星滑落. 狗哥是幸运的,他在两秒钟内看到了十七颗彗星划过天际,作为打ACM的学者,自然不会有「稳定-1」情 ...

  3. “字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛

    a.hzy 和zsl 的生存挑战 思路:看见"假设他们都足够机智"就够了,全输出1.00就ac #include<bits/stdc++.h> #define INF ...

  4. 文远知行杯广东工业大学第十六届程序设计竞赛ABEFHI(记录)

    文远知行杯广东工业大学第十六届程序设计竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ大学ACM校赛新生赛是面向ACM/ICPC/CCPC/区域赛校队选手,巩固经典专 ...

  5. 文远知行杯广东工业大学第十六届程序设计竞赛(题解)

    文远知行杯广东工业大学第十六届程序设计竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ A:思维题 #include<bits/stdc++.h> usi ...

  6. 文远知行杯广东工业大学第十六届程序设计竞赛 E爬塔

    题目描述 Alice最近迷上了杀怪爬塔的游戏,在塔中有n层关卡,在通过第i层关卡后Alice会走上第i+1层.每个关卡中可能会获得女神的祝福或者遇到怪物.如果得到女神的祝福,Alice生命值会+1,如 ...

  7. 文远知行杯广东工业大学第十六届程序设计竞赛错题笔记

    目录 官网链接 A 区间最大值 F 一个很大的数 I V字钩爪 官网链接 A 区间最大值 题目描述 长度为 n 的数组 a,下标从1开始,定义 a[i]=n%i 有 m 组询问 {L,R},求 max ...

  8. 文远知行杯广东工业大学第十六届程序设计竞赛 A 区间最大值

    题目链接:https://ac.nowcoder.com/acm/contest/30896/A 题目描述 长度为 n 的数组 a,下标从 1 开始,定义 a [ i ] = n % i a[i]=n ...

  9. 文远知行杯广东工业大学第十六届程序设计竞赛

    A: 长度为 n 的数组 a,下标从1开始,定义 a[i]=n%ia[i]=n \% ia[i]=n%i 有 m 组询问 {L,R},求 maxi=LRa[i]max_{i=L}^{R} a[i]ma ...

最新文章

  1. 01-1. 最大子列和问题
  2. SAP ABAP和Linux系统里如何检查网络传输的数据量
  3. Maven,在pom.xml配置JDK 9版本。
  4. ORACLE快速遍历树及join基表很大的性能问题
  5. mysql数据库的服务无法启动,mysql服务无法启动,服务没有报告任何错误
  6. html雪花特效卡盟,吃鸡卡盟忍者必需死3 12月忍界试卷谜底一览
  7. dcs world f15c教学_烟台TSXP57353M【四点零自动化】DCS系统
  8. 【转】Filter Concatenation理解
  9. PIC单片机汇编指令集合
  10. 基于51单片机的对讲机原理图PCB程序设计
  11. 软件开发项目流程 - 立项
  12. Flutter应用程序版本更新与自动升级配置方法
  13. jquery Ajax回调函数
  14. leetcode-Algorithms-350|两个数组的交集II
  15. php 图片后缀,php获取图片格式(图片后缀)
  16. Master of Typing Tutor 1.2.3 特别版 Mac 打字练习软件掌握打字
  17. Setuptools(Python打包工具)
  18. 计算机组成原理---指令系统
  19. air游戏接入小米支付sdk
  20. 带缓冲的输入/输入流

热门文章

  1. ollections 模块之OrderedDict
  2. 原版英文书籍《Linux命令行》阅读记录1 | 什么是shell?
  3. 基于vue2.0 + elementUI 后台管理平台
  4. 微信公众平台中的openid是什么
  5. 由dataview生成对应的datatable的方法
  6. 漫步最优化三十六——基本共轭方向法
  7. 关联性挖掘--Apriori算法详解
  8. mysql 分库分表 建表,mysql 分库分表 建表MySQL常用操作
  9. roobo机器人怎么唱歌_抖音文案怎么写?如何写出引发共鸣的标题文案?让作品上大热门...
  10. 网络爬虫之httpclient的使用