Number of even numbers 3 total time limit: 10000ms single test point time limit: 1000ms memory limit: 131072kB "description"
In all n digits, how many of the numbers have an even number 3?
Input
One line to the word n,n<=1000
Output
Title
"Sample Input"
2
"Sample Output"
73
"Solution"
DP[I][1] indicates that the number of I digits has an odd number of three, and Dp[i][0] indicates an even number of three. DP[I][1] can add 0 1 2 4 5 6 7 8 9 and Dp[i-1][0] First add 3 transfer, dp[i][0] in the same form as dp[i-1][1]. Note that the first 0 cannot be added when i==n.
AC Code:
1#include <cstdio>2 intN;3 intdp[1010][2];4 intMain () {5scanf"%d", &n); dp[1][1]=1; dp[1][0]=9;6 for(intI=2; i<=n;++i) {7 intK=i==n?8:9;8dp[i][0]=dp[i-1][0]%12345*k+dp[i-1][1]%12345;9dp[i][1]=dp[i-1][1]%12345*k+dp[i-1][0]%12345;Ten } Oneprintf"%d", dp[n][0]%12345); A return 0; -}
"OpenJudge9272" "DP" an even number of digits 3