HDU 3652 数位DP
2014-08-19 14:38
232 查看
#include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <queue> #include <stack> #include <fstream> #include <numeric> #include <iomanip> #include <bitset> #include <list> #include <stdexcept> #include <functional> #include <utility> #include <ctime> #include <cassert> #include <complex> using namespace std; typedef long long ll; typedef long double ld; const int int_max = 0x07777777; const int int_min = 0x80000000; const int inf=0x20202020; const ll mod=1000000007; const double eps=1e-9; const double pi=3.1415926535897932384626; const int DX[]={1,0,-1,0},DY[]={0,1,0,-1}; ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} bool cmp (const void *a , const void *b ) { return *(int *)a < *(int *)b; } int n; int dp[12][10][2][13]; //dp[i][j][k][l] 表示位数的i,最高位为j,k(0表示不存在13,1表示存在13),l表示被13取模的结果 ,满足上述条件的数的个数。 int a[12]; int solve (int len){ int sum = 0, tempsum=0, flag = 0; ll t[11]; t[1] = 1; for(int i = 2; i < 11; i++) t[i] = 10*t[i-1]; for(int i = len; i >= 1; i--){ for(int x = 0; x < a[i]; x++){ int lll = 13-tempsum; lll %= 13; lll = lll < 0 ? lll+13 : lll; sum += dp[i][x][1][lll]; if(flag || (x==3 && a[i+1]==1)){ sum += dp[i][x][0][lll]; } } if(a[i]==3&&a[i+1]==1) flag = 1; tempsum += a[i]*t[i]; } return sum; } int main() { memset(dp,0,sizeof(dp)); dp[0][0][0][0] = 1; for(int i = 1; i < 12; i++){ for(int j = 0; j < 10; j++){ for(int k = 0; k < 2; k++){ for(int l = 0; l < 13; l++){ for(int x = 0; x < 10; x++){ if(k==0){ if(j==1 && x==3) continue; int lll = l - j*(int)pow(10,i-1); lll %= 13; lll = lll < 0 ? lll+13 : lll; dp[i][j][k][l] += dp[i-1][x][k][lll]; }else{ int lll = l - j*(int)pow(10,i-1); lll %= 13; lll = lll < 0 ? lll+13 : lll; dp[i][j][k][l] += dp[i-1][x][k][lll]; if(j==1 &&x==3) dp[i][j][k][l] += dp[i-1][x][0][lll]; } } } } } } while(scanf("%d", &n)!=EOF){ memset(a,0,sizeof(a)); n++; int len = 0; while(n){ a[++len] = n%10; n /= 10; } int ret = solve(len); printf("%d\n", ret); } }
相关文章推荐
- HDU 3652 B-number(数位DP)
- hdu 3652 B-number(数位DP,4级)
- HDU 3652——B-number(数位DP)
- HDU 3652 B-number(数位dp模版)
- HDU 3652 B-number(数位DP)
- hdu 3652 B-number (数位DP)
- HDU 3652 数位DP
- HDU 3652--B-number(数位dp)
- HDU 3652 数位DP
- HDU 3652 B-number (数位DP)
- HDU 3652 B-number(数位DP)
- hdu 3652 数位DP
- hdu 3652(数位dp)
- HDU 3652 数位DP(递归)
- [HDU 3652]B-number[数位DP]
- hdu 3652 -数位dp
- HDU 3652 B-number(数位DP)
- HDU 3652 B-number (数位DP)
- HDU-3652 B-number 数位DP
- HDU 3652:B-number(数位DP)