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

【HDOJ】1508 Alphacode

时间:2015-10-31 22:49:42      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

简单DP。考虑10、20(出现0只能唯一组合)。01(不成立)。

 1 /* 1508 */
 2 #include <iostream>
 3 #include <string>
 4 #include <map>
 5 #include <queue>
 6 #include <set>
 7 #include <stack>
 8 #include <vector>
 9 #include <deque>
10 #include <algorithm>
11 #include <cstdio>
12 #include <cmath>
13 #include <ctime>
14 #include <cstring>
15 #include <climits>
16 #include <cctype>
17 #include <cassert>
18 #include <functional>
19 #include <iterator>
20 #include <iomanip>
21 using namespace std;
22 //#pragma comment(linker,"/STACK:102400000,1024000")
23 
24 #define sti                set<int>
25 #define stpii            set<pair<int, int> >
26 #define mpii            map<int,int>
27 #define vi                vector<int>
28 #define pii                pair<int,int>
29 #define vpii            vector<pair<int,int> >
30 #define rep(i, a, n)     for (int i=a;i<n;++i)
31 #define per(i, a, n)     for (int i=n-1;i>=a;--i)
32 #define clr                clear
33 #define pb                 push_back
34 #define mp                 make_pair
35 #define fir                first
36 #define sec                second
37 #define all(x)             (x).begin(),(x).end()
38 #define SZ(x)             ((int)(x).size())
39 #define lson            l, mid, rt<<1
40 #define rson            mid+1, r, rt<<1|1
41 
42 const int maxn = 1e5+5;
43 char s[maxn];
44 __int64 dp[maxn];
45 
46 int main() {
47     ios::sync_with_stdio(false);
48     #ifndef ONLINE_JUDGE
49         freopen("data.in", "r", stdin);
50         freopen("data.out", "w", stdout);
51     #endif
52     
53     int len;
54     __int64 ans;
55     
56     while (scanf("%s", s+1)!=EOF && s[1]!=0) {
57         len = strlen(s+1);
58         rep(i, 1, len+1)    s[i] -= 0;
59         
60         dp[0] = 1;
61         rep(i, 1, len+1) {
62             if (s[i] == 0) {
63                 dp[i] = dp[i-2];
64             } else if (i>1 && s[i-1]>0 && 10*s[i-1]+s[i]<=26) {
65                 dp[i] = dp[i-1] + dp[i-2];
66             } else {
67                 dp[i] = dp[i-1];
68             }
69         }
70         
71         ans = dp[len];
72         printf("%I64d\n", ans);
73     }
74     
75     #ifndef ONLINE_JUDGE
76         printf("time = %d.\n", (int)clock());
77     #endif
78     
79     return 0;
80 }

 

【HDOJ】1508 Alphacode

标签:

原文地址:http://www.cnblogs.com/bombe1013/p/4926235.html

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