题目大意:有一个关于 简单加法表达式 的定义告诉你,就是 选一个数字i 如果 i+(i+1)+(i+2) 它的和,没有任何一位进位的话,那就是 一个i的简单加法表达式,求小于n的表达式数目。
题解:排列组合分类讨论即可……
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
#include <cstdio> #include <cmath> #include <cstring> using
namespace std; char
s[15]; int solve(int
i,int p){ if(p==1)return
s[i]>‘2‘?3:s[i]-‘0‘+1; if(s[i]>‘3‘){return
(int)pow(4.0,p-1)*3;} else{ int
t1=(int)(pow(4.0,p-2)*3*(s[i]-‘0‘)); int
t2=solve(i+1,p-1); return
t1+t2; } } int
main(){ __int64
n; while(scanf("%I64d",&n)!=EOF){ n--; sprintf(s,"%I64d",n); printf("%d\n",solve(0,strlen(s))); } return
0; } |
HDU 2451 Simple Addition Expression,布布扣,bubuko.com
HDU 2451 Simple Addition Expression
原文:http://www.cnblogs.com/forever97/p/3662245.html