码迷,mamicode.com
首页 > Windows程序 > 详细

【BZOJ1026】【SCOI2009】windy数

时间:2016-02-15 16:10:35      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

传送门~:http://www.lydsy.com/JudgeOnline/problem.php?id=1026

数位dp傻题QaQ

技术分享
 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <iostream>
 5 using namespace std;
 6 int f[15][15], A, B, da[15];
 7 void get_ready(){
 8     for (int i = 0; i <= 9; i++) f[1][i] = 1; 
 9     for (int i = 2; i <= 10; i++){
10         for (int j = 0; j <= 9; j++) {
11             for (int k = 0; k <= 9; k++) {
12                 if (abs(j-k) >= 2)    f[i][j] += f[i-1][k];
13             }
14         }
15     }
16 }
17 
18 int calc(int a){
19     if (a == 0) return 0;
20     int ret = 0, len = 0;
21     do{
22         da[++len] = a % 10;
23         a /= 10;
24     }while(a);
25     for (int i = 1; i < len; i++)
26         for (int j = 1; j <= 9; j++)
27             ret += f[i][j];
28     for (int i = 1; i < da[len]; i++) ret += f[len][i];
29     for (int i = len-1; i > 0; i--) {
30         for (int j = 0; j < da[i]; j++)
31             if (abs(j-da[i+1]) >= 2) ret += f[i][j];
32         if (abs(da[i]-da[i+1]) < 2) break;
33     }
34     return ret;
35 }
36 
37 int main(){
38     freopen("bzoj1026.in", "r", stdin);
39     freopen("bzoj1026.out", "w", stdout);
40     get_ready();
41     scanf("%d%d", &A, &B);
42     printf("%d\n", calc(B+1) - calc(A));
43     return 0;
44 }
_(:з」∠)_

 

【BZOJ1026】【SCOI2009】windy数

标签:

原文地址:http://www.cnblogs.com/Lukaluka/p/5190624.html

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