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时,还是根据前面的余数分布决定接下来可以填什么数。

暴力递推

#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=+;
const int MOD=;
const double PI = acos(-1.0);
const double EXP = 1E-;
const int INF = 0x3f3f3f3f;
ll t,n,m,k,q,ans;
ll a[];
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
while(~scanf("%lld",&n)){
memset(a,,sizeof(a));
a[]=;
a[]=;
a[]=;
a[]=;
for(int i=;i<=n;i++){
int x=a[],y=a[],z=a[],t=a[];
a[]=(x*+y*+z*+t*)%MOD;
a[]=(x*+y*+z*+t*)%MOD;
a[]=(x*+y*+z*+t*)%MOD;
a[]=(x*+y*+z*+t*)%MOD;
}
cout<<a[]<<endl;
}
//cout << "Hello world!" << endl;
return ;
}

很明显肯定会超时。

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

矩阵快速幂

#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=;
const int MOD=;
const double PI = acos(-1.0);
const double EXP = 1E-;
const int INF = 0x3f3f3f3f;
ll t,n,m,k,q,ans;
ll a[][]={,,,,,,,,,,,,,,,};
ll b[][]={,,,,,,,,,,,,,,,};
int tmp[N][N];
void multi(ll a[][],ll b[][])
{
memset(tmp,,sizeof tmp);
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%MOD;
for(int i=;i<;i++)
for(int j=;j<;j++)
a[i][j]=tmp[i][j];
}
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
while(~scanf("%lld",&n)){
ll a[][]={,,,,,,,,,,,,,,,};
ll b[][]={,,,,,,,,,,,,,,,};
n--;
while(n){
if(n&){
multi(a,b);
}
multi(b,b);
n/=;
}
cout<<a[][]<<endl;
}
//cout << "Hello world!" << endl;
return ;
}

The Digits String的更多相关文章

  1. L The Digits String(没有写完,有空补)

    链接:https://ac.nowcoder.com/acm/contest/338/L来源:牛客网 Consider digits strings with length n, how many d ...

  2. python中string模块

    >>> import string >>> string.ascii_letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL ...

  3. python string module

    String模块中的常量 >>> import string >>> string.digits ' >>> string.letters 'ab ...

  4. [Swift]LeetCode949. 给定数字能组成的最大时间 | Largest Time for Given Digits

    Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour t ...

  5. (九)random、os、time、datetime、hashlib、pymysql、excel、sys、string相关模块

    1.random模块 1 import random,string 2 print(string.printable) #代表所有的 数字+字母+特殊字符 3 4 print(random.randi ...

  6. python 加密算法及其相关模块的学习(hashlib,random,string,math)

    加密算法介绍 一,HASH Hash,一般翻译做“散列”,也有直接音译为”哈希”的,就是把任意长度的输入(又叫做预映射,pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种 ...

  7. 738. Monotone Increasing Digits 单调递增的最接近数字

    [抄题]: Given a non-negative integer N, find the largest number that is less than or equal to N with m ...

  8. Python 3之str类型、string模块学习笔记

    Windows 10家庭中文版,Python 3.6.4, Python 3.7官文: Text Sequence Type — str string — Common string operatio ...

  9. python拓展2 collections模块与string模块

    知识内容 1.collections模块介绍 2.collections模块使用 3.string模块介绍及使用 一.collections模块介绍 collections模块中提供了很多python ...

随机推荐

  1. 2016 Multi-University Training Contest 4 部分题解

    1001,官方题解是直接dp,首先dp[i]表示到i位置的种类数,它首先应该等于dp[i-1],(假设m是B串的长度)同时,如果(i-m+1)这个位置开始到i这个位置的这一串是和B串相同的,那么dp[ ...

  2. ettercap局域网DNS切换到恶意网址

    ettercap -i eth0 -Tq -M arp:remote -P dns_spoof /// /// Dns欺骗--Ettercap工具进行Dns欺骗 转载至 https://blog.cs ...

  3. 【面试】Spring 执行流程

    Spring Aop的实现原理: AOP 的全称是  Aspect Orient Programming  ,即面向切面编程.是对 OOP (Object Orient Programming) 的一 ...

  4. tp5 模型中 关联查询(省去了foreach写法)

    1.控制器中 $list = Userlawsbook::where($where)->with('lawsbook')->paginate(7);  // 此处查出来为数组对象 dump ...

  5. Redis内存满了的几种解决方法(内存淘汰策略与Redis集群)

    1,增加内存: 2,使用内存淘汰策略. 3,Redis集群. 重点介绍下23: 第2点: 我们知道,redis设置配置文件的maxmemory参数,可以控制其最大可用内存大小(字节). 那么当所需内存 ...

  6. pandas.Series.value_counts

    pandas.Series.value_counts Series.value_counts(normalize=False, sort=True, ascending=False, bins=Non ...

  7. 码云上webide怎么提交

    修改后想提交,它会提示:“暂存文件后才能提交”, 我拿放大镜找遍了整个界面也没找到“暂存”按钮, 原来,文件旁边那个+号就是暂存,好歹鼠标方式去之后给个tip,服了. 点一下这个加号,提交按钮就可用了 ...

  8. Uboot启动分析之Start.S

    1.start.S引入 1.1.u-boot.lds中找到start.S入口 1)C语言中代码的分析第一步就是找到main.c,找到函数的入口 2)uboot中因为有汇编语言参与所以就不能像C一样.U ...

  9. ControlTemplate in WPF —— Calendar

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  10. Mysql中用SQL增加、删除、修改(包括字段长度/注释/字段名)总结

    转: Mysql中用SQL增加.删除.修改(包括字段长度/注释/字段名)总结 2018年09月05日 10:14:37 桥Dopey 阅读数:1830   版权声明:本文为博主原创文章,未经博主允许不 ...