【题目链接】:http://codeforces.com/problemset/problem/507/D

【题意】



让你找符合这样数字的数的个数:

1.有n个数码

2.某个后缀%k的值为0

3.大于0

【题解】



数位DP;

设f[i][j][0]和f[i][j][1]分别表示;

(把最后的数字倒过来)

前i个数字组成的数%k的结果为j;

且前i-1个数字没有出现过%k结果为0;

前i-1个数字有出现过%k结果为0的方案数;

枚举新添加的一位;

看看新的取余值是啥;

然后想一想转移方程就好;

dp[0][0][0]=1;

(一开始那个不算取余值为0)

(第一位必须为正数!)

最后累计∑f[n][0..k-1][1];

输出答案;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1100;
const int K = 110; LL n,k,m,dp[N][K][2],pre[N]; //0不含%k==0
//1含%k==0 int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> k >> m;
pre[0] = 1%k;
rep1(i,1,1000)
pre[i] = (pre[i-1]*10)%k;
dp[0][0][0] = 1;
rep1(i,0,n-1)
rep1(j,0,k-1)
rep1(num,(i==(n-1)?1:0),9)
{
LL now = (j+num*pre[i])%k;
if (now==0 && num!=0)
{
dp[i+1][now][1] = (dp[i+1][now][1] + dp[i][j][0])%m;
}
else
//now!=0 || (now==0 && num==0)
dp[i+1][now][0] = (dp[i+1][now][0] + dp[i][j][0])%m;
dp[i+1][now][1] = (dp[i+1][now][1] + dp[i][j][1])%m;
}
LL ans = 0;
rep1(i,0,k-1)
ans = (ans + dp[n][i][1])%m;
cout << ans << endl;
return 0;
}

【codeforces 508D】The Maths lecture的更多相关文章

  1. 【codeforces 508D】Tanya and Password

    [题目链接]:http://codeforces.com/problemset/problem/508/D [题意] 给你一个字符的所有连续3个的子串; 让你复原出原串; (包含小写.大写字母以及数字 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【39.29%】【codeforces 552E】Vanya and Brackets

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. 【hdu 6438】Buy and Resell

    [链接] 我是链接,点我呀:) [题意] 有一个物品的价格在1..n这些位置各不相同. 你初始有无限的钱. 问你从1走到n. 你每次可以选择买入一个或者卖出一个该种物品(或啥都不做) 问你最后的最大利 ...

  2. 【codeforces 799A】Carrot Cakes

    [题目链接]:http://codeforces.com/contest/799/problem/A [题意] 你有一个烤炉; 每t秒能同时烤出k个蛋糕; 你可以在第一个烤炉在烤的时候;同时花费d秒建 ...

  3. 使用Spring Initializer快速创建Spring Boot项目

    目录结构 IDE都支持使用Spring的项目创建向导快速创建一个Spring Boot项目:选择我们需要的模块:向导会联网创建Spring Boot项目:默认生成的Spring Boot项目: 主程序 ...

  4. POJ 3228 Gold Transportation

    Gold Transportation Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Ori ...

  5. C# 知识点集合

    1.一个Visual studio软件进程只能打开一个程序集,但是一个程序集可以加载多个项目,通过程序集的添加功能可以实现. 2.F11单步调试,F10跨程序调试(一般用不到) 3.VS如何快速的切换 ...

  6. pythonWeb -- Django开发- Admin

    [第一次使用Admin 要创建超级用户账号] 1.\ python manage.py createsuperuser You have 1 unapplied migration(s). Your ...

  7. plsql解决64位解决办法

    plsql解决64位解决办法 设置PLSQL Developer访问本机64位Oracle 由于在本机Windows Server 2008 R2 X64上安装了64位的Oracle 11.2.0.1 ...

  8. 第18题 Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  9. https 证书 certbot-auto执行错误

    报错:ImportError: /root/.local/share/letsencrypt/lib/python2.7/site-packages/cryptography/hazmat/bindi ...

  10. ADT、C和Java

    <编程导论(Java)·5 链表.数组和栈> 数据抽象使得用户程序猿在编写客户程序时,摆脱该数据类型的实现细节而只关心该数据类型的接口.在计算机科学中.有一些重要的数据抽象--数据结构,应 ...