https://ac.nowcoder.com/acm/contest/338/L

题解:

当n==1时,0-9填上的话,对4取余,分别是余数为0的3个,1的3个,2的2个,3的2个;

当n==2时,因为一个数的时候有3323的余数个数分布,如果第2个填上数可以使原来的余数变成0或者保持零,那么可以填上;

当n>=3时,还是根据前面的余数分布决定接下来可以填什么数。

暴力递推

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=2019;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
ll t,n,m,k,q,ans;
ll a[5];
char str;
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifwhile(~scanf("%lld",&n)){memset(a,0,sizeof(a));a[0]=3;a[1]=3;a[2]=2;a[3]=2;for(int i=2;i<=n;i++){int x=a[0],y=a[1],z=a[2],t=a[3];a[0]=(x*3+y*2+z*2+t*3)%MOD;a[1]=(x*3+y*3+z*2+t*2)%MOD;a[2]=(x*2+y*3+z*3+t*2)%MOD;a[3]=(x*2+y*2+z*3+t*3)%MOD;}cout<<a[0]<<endl;}//cout << "Hello world!" << endl;return 0;
}

很明显肯定会超时。

a数组和递推a数组的系数可以构成同一个方矩阵,那么可以通过矩阵快速幂减少时间复杂度。所求的答案就是方阵a的n-1次幂中的a[]0[0];

矩阵快速幂

参考文章:https://blog.csdn.net/weixin_43272781/article/details/85939539

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=10;
const int MOD=2019;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
ll t,n,m,k,q,ans;
ll a[5][4]={3,3,2,2,3,3,2,2,3,3,2,2,3,3,2,2};
ll b[5][4]={3,3,2,2,3,3,2,2,3,3,2,2,3,3,2,2};
int tmp[N][N];
void multi(ll a[][4],ll b[][4])
{memset(tmp,0,sizeof tmp);for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++)tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%MOD;for(int i=0;i<4;i++)for(int j=0;j<4;j++)a[i][j]=tmp[i][j];
}
char str;
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifwhile(~scanf("%lld",&n)){ll a[5][4]={3,3,2,2,2,3,3,2,2,2,3,3,3,2,2,3};ll b[5][4]={3,3,2,2,2,3,3,2,2,2,3,3,3,2,2,3};n--;while(n){if(n&1){multi(a,b);}multi(b,b);n/=2;}cout<<a[0][0]<<endl;}//cout << "Hello world!" << endl;return 0;
}

The Digits String相关推荐

  1. 湖南大学第十四届ACM程序设计新生杯(重现赛)L-The Digits String (矩阵快速幂)

    题目链接 题目描述 Consider digits strings with length n, how many different strings have the sum of digits a ...

  2. python中string.digits_Python string.hexdigits方法代码示例

    本文整理汇总了Python中string.hexdigits方法的典型用法代码示例.如果您正苦于以下问题:Python string.hexdigits方法的具体用法?Python string.he ...

  3. python中uppercase是什么意思_Python string.ascii_uppercase方法代码示例

    本文整理汇总了Python中string.ascii_uppercase方法的典型用法代码示例.如果您正苦于以下问题:Python string.ascii_uppercase方法的具体用法?Pyth ...

  4. python中uppercase是什么意思_Python string.uppercase方法代码示例

    本文整理汇总了Python中string.uppercase方法的典型用法代码示例.如果您正苦于以下问题:Python string.uppercase方法的具体用法?Python string.up ...

  5. 深度学习 -- TensorFlow(项目)验证码生成与识别(多任务学习)

    目录 基础理论 一.生成验证码数据集 1.生成验证码训练集 1-0.判断文件夹是否为空 1-1.创建字符集(数字.大小写英文字母) 1-2.随机生成验证码(1000个,长度为4) 2.生成验证码测试集 ...

  6. 如何在一场面试中展现你对Python的coding能力?| 技术头条

    点击上方↑↑↑蓝字关注我们~ 作者 | wLsq 来源 | Python数据科学(ID:PyDataScience) 如果你已经通过了招聘人员的电话面试,那么下面正是该展现你代码能力的时候了.无论是练 ...

  7. leetcode17. 电话号码的字母组合--每天刷一道leetcode算法系列!

    作者:reed,一个热爱技术的斜杠青年,程序员面试联合创始人 前文回顾: leetcode1. 两数之和--每天刷一道leetcode系列! leetcode2. 两数相加--每天刷一道leetcod ...

  8. 安恒赛php_安恒11月月赛周周练writeup

    前言 11月月赛 完美错过时间,正好有周周练,基本都是一样月赛的web,记录下write up 手速要快 这题是10月月赛中的一题,直接看我上次的writeup:安恒月赛(十)web-2题writeu ...

  9. python 随机生成密码

    python 随机生成密码 #!/usr/bin/env python # -*- encoding: utf-8 -*- """ @Introduce : 随机生成密码 ...

最新文章

  1. 题目1023:EXCEL排序
  2. Css2.0+Css3.0+jQuery手册 chm
  3. 成功解决Exception “unhandled ModuleNotFoundError“No module named ‘sklearn.neighbors.classification‘
  4. boost::static_mutex 的测试程序
  5. 《操作系统实现之路》源代码下载路径及求助途径
  6. 第三方seo关键词优化工具推荐
  7. 控制浏览器增加新页签的js_技术网站重写复制按键 js 跳转到注册页,就能增加用户?...
  8. 中国联通:已率先开通国内40个城市的5G试验网络
  9. java 文件无法下载_无法从Java中的URL下载文件
  10. Matlab学习:读取excel中数据
  11. 蛮牛教育Unity Shader从入门到精通:第十节课Shader问题
  12. imageai--自动机器学习初体验
  13. GD32F450以太网(1):ETH 外设接口简介
  14. 中层领导力:西点军校和哈佛大学共同讲授的领导力教程读书摘要
  15. 不可错过的《一步一步学Spring Boot》视频教程
  16. 遥感应用发展观察(更新)
  17. 使用matlab绘制条形图、面积图、饼图、柱状图
  18. 如何在Eclipse 中将隐藏的包给显示出来
  19. 计算机主机放到什么位置最好,电脑桌放在哪个位置好 这些建议你一定要看
  20. CryptoJS与JSEncrypt 加密算法

热门文章

  1. linux上查看gitlab日志,如何查看Gitlab的版本?
  2. linux的write是线程安全的吗,socket的write/send还是是否是线程安全?
  3. IDM下载速度慢解决方案全网搜集持续更新
  4. 为什么进mysql需要用户和密码了_centos5安装 mysql 提示需要用户及密码进入?
  5. android 自定义刷新控件,Android开发中MJRefresh自定义刷新动画效果
  6. python代码用c语言封装_使用C语言扩展Python程序的简单入门指引
  7. 二十一、String、StringBuffer和StringBuilder的区别是什么?
  8. keras从入门到放弃(十二)卷积神经网络
  9. Java web项目报错 Java compiler level does not match the version of the installed Java project facet.
  10. 报名|第2期“DI极客说”,揭秘决策AI创新应用带来的行业变革