码迷,mamicode.com
首页 > 其他好文 > 详细

【例3.5】位数问题

时间:2017-10-15 17:45:30      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:链接   end   http   限制   答案   情况   输出   数字   style   

【例3.5】位数问题

链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1313


时间限制: 1000 ms         内存限制: 65536 KB

【题目描述】

在所有的N位数中,有多少个数中有偶数个数字3?由于结果可能很大,你只需要输出这个答案对12345取余的值。

【输入】

读入一个数N。

【输出】

输出有多少个数中有偶数个数字3。

【输入样例】

2

【输出样例】

73
题解:i位数偶数个3:i-1位数偶数3前面加0,1,2,4……九个数,奇数个3前面加3,同理得奇数情况,到最后一次去掉0的情况
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long f[5001][2];
int main()
{
    int n;
    cin>>n;
    f[1][0]=9;
    f[1][1]=1;
    int k=9;
    for(int i=2;i<=n;i++)
    {
        if(i==n)k--;
        f[i][0]=(f[i-1][0]*k+f[i-1][1])%12345;
        f[i][1]=(f[i-1][1]*k+f[i-1][0])%12345;
    }
    cout<<f[n][0]<<endl;
}

 

【例3.5】位数问题

标签:链接   end   http   限制   答案   情况   输出   数字   style   

原文地址:http://www.cnblogs.com/EdSheeran/p/7672571.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!