【HDU3652】B-number 数位DP
B-number
#include <stdio.h>
#include <string.h>
int n,m;
int v[20];
int f[12][10][13],g[12][10][13],t[12];
int main()
{
int i,j,k,l,ans,rem,x;
t[1]=1;
for(i=2;i<=10;i++) t[i]=t[i-1]*10;
for(i=0;i<=9;i++) g[1][i][i]=1;
for(i=2;i<=10;i++)
{
for(j=0;j<=9;j++)
{
for(k=0;k<=9;k++)
{
for(l=0;l<=12;l++)
{
if(j==1&&k==3)
{
f[i][j][l]+=(j*t[i]+(k+1)*t[i-1]-1-l)/13-(j*t[i]+k*t[i-1]-1-l)/13;
}
else
{
f[i][j][l]+=f[i-1][k][((l-j*t[i])%13+13)%13];
g[i][j][l]+=g[i-1][k][((l-j*t[i])%13+13)%13];
}
}
}
}
}
while(scanf("%d",&n)!=EOF)
{
memset(v,0,sizeof(v));
rem=m=ans=0; //此时答案的后i位对13取模应该等于rem
x=n;
while(x)
{
v[++m]=x%10;
x/=10;
}
for(i=m;i>=1;i--)
{
for(j=0;j<v[i];j++) ans+=f[i][j][rem];
if(v[i]>3&&v[i+1]==1)
{
ans+=g[i][3][rem];
}
if(v[i]==3&&v[i+1]==1)
{
ans+=n/13-(n/t[i]*t[i]-1)/13;
break;
}
rem=((rem-v[i]*t[i])%13+13)%13;
}
printf("%d\n",ans);
}
return 0;
}
【HDU3652】B-number 数位DP的更多相关文章
- 多校5 HDU5787 K-wolf Number 数位DP
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- HDU 5787 K-wolf Number 数位DP
K-wolf Number Problem Description Alice thinks an integer x is a K-wolf number, if every K adjacen ...
- Fzu2109 Mountain Number 数位dp
Accept: 189 Submit: 461Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description One ...
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- beautiful number 数位DP codeforces 55D
题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...
- FZU - 2109 Mountain Number 数位dp
Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...
- BNU 13024 . Fi Binary Number 数位dp/fibonacci数列
B. Fi Binary Number A Fi-binary number is a number that contains only 0 and 1. It does not conta ...
- hdu 5898 odd-even number(数位dp)
Problem Description For a number,if the length of continuous odd digits is even and the length of co ...
随机推荐
- Android 实现类似微信客户端朋友圈更新提示的小红点&栏目订阅
用到的类: com.jauker.widget.BadgeView 实现代码: BadgeView imageBadge = new BadgeView(getContext()); imageBad ...
- NYOJ题目893十字架
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsYAAAQRCAIAAACl4dlPAAAgAElEQVR4nO3dO1Ljyv834P8myFkIsR
- NYOJ题目768移位密码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtIAAAJqCAIAAACJkTDlAAAgAElEQVR4nO3du3Ljvpa34b4J574Qx7
- PAL/NTSC 制电视广播技术有关知识--FPGA
1.PAL和NTSC的区别 常见的电视信号制式是PAL和NTSC,另外还有SECAM等. NTSC即正交平衡调幅制,PAL为逐行倒像正交平衡调幅制. (1)PAL电视标准 PAL电视标准,每秒25帧 ...
- Android OkHttp完全解析 --zz
参考文章 https://github.com/square/okhttp http://square.github.io/okhttp/ 泡网OkHttp使用教程 Android OkHttp完全解 ...
- Pyqt QListWidget之缩略图列表
QListWidget 可以设置模型setViewMode 当setViewMode值为QListView.IconMode 表示Icon模式 以下代码来自Pyqt Example #!/usr/b ...
- win7Java开发环境配置
win7下Java开发环境的配置 首先下载符合操作系统版本的jdk,比如最新的jdk8: 下载链接:http://www.oracle.com/technetwork/java/javase/down ...
- hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- Oracle 备份与恢复介绍
一.Oracle备份方式分类:Oracle有两类备份方式:(1)物理备份:是将实际组成数据库的操作系统文件从一处拷贝到另一处的备份过程,通常是从磁盘到磁带.物理备份又分为冷备份.热备份: (2)逻 ...
- ASP.NET Identity 3.0教程
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:我相信有些人和我一样,已经开始把ASP.NET 5用于产品开发了.不过现在最大的问题是 ...