【HDOJ】2266 How Many Equations Can You Find

简单DFS。

 #include <cstdio>
#include <cstring> #define MAXN 15 char str[MAXN];
__int64 x;
int n; void dfs(int s, __int64 v) {
int i;
__int64 tmp = ;
if (str[s] == '\0') {
if (v == x)
++n;
return ;
} for (i=s; str[i]; ++i) {
tmp = *tmp + str[i] - '';
dfs(i+, v+tmp);
if (s)
dfs(i+, v-tmp);
}
} int main() { while (scanf("%s %I64d", str, &x) != EOF) {
n = ;
dfs(, );
printf("%d\n", n);
} return ;
}
上一篇:WAPI


下一篇:MVC 局部加载页面的实例