noip2008提高组——火柴棒等式
2015-02-08 10:24
218 查看
这道题算法上 就是裸dfs 吧
主要是看代码能力。。(这是一个悲伤的故事。。QAQ)
细节上只要注意0不可以开头就好了
有一个小优化
把加号和等号一起看做分隔符号
就只用数分割号的个数 模拟起来就好做多了
#include<cstdio>
#include<cstring>
using namespace std;
const int use[]={6,2,5,5,4,5,6,3,7,6,2};
int n,ans;
char cal[100];
bool getnum(int len,int &now,int &i,int jh)
{
int bz=0;
while(1)
{
if(cal[i]>'9')
break;
if(i==len+1)
{
bz=1;break;
}
if(now==-1)
{
now=cal[i]-'0';
i++;
continue;
}
now*=10;
now+=cal[i]-'1'+1;
i++;
}
if(jh==1)
bz=0;
if(now==-1||bz==1)
return false;
i++;
return true;
}
void work()
{
int now=-1,now1=-1,res=-1;
int len=strlen(cal)-1;
int cnt=0;
for(int i=0;i<=len;i++)
if(cal[i]>'9')
cnt++;
if(cnt>2)
return;
int i=0;
int bz=0;
if(!getnum(len,now,i,0))
return;
if(!getnum(len,now1,i,0))
return;
if(!getnum(len,res,i,1))
return;
if(res==now+now1)
ans++;
}
void solve(int depth,int now)
{
if(depth>n)
return;
if(depth==n)
{
work();
return;
}
for(int i=0;i<=10;i++)
{
if(cal[now-1]=='0'&&i==0)
continue;
if(cal[now-1]=='0'&&i!=10)
continue;
cal[now]=i+'1'-1;
solve(depth+use[i],now+1);
cal[now]=0;
}
}
int main()
{
scanf("%d",&n);
solve(0,0);
printf("%d",ans);
}
相关文章推荐
- 洛谷-火柴棒等式-NOIP2008提高组复赛
- NOIP 2008 提高组 复赛 matches 火柴棒等式
- NOIP2008提高组火柴棒等式(模拟)——yhx
- 火柴棒等式(洛谷 1149 && NOIp2008 提高组 T2 )
- [NOIP2008] 提高组 洛谷P1149 火柴棒等式
- 2008NOIp提高组 火柴棒等式
- 【提高组NOIP2008】火柴棒等式
- 【枚举】Vijos P1496 火柴棒等式 【NOIP2008提高组第二题】
- 洛谷 P1149 火柴棒等式2008 NOIp提高组
- NOIp2008 火柴棒等式
- noip2008 火柴棒等式 (暴力枚举)
- [noip模拟]四道题 noip2008 笨小猴 noip2008 火柴棒等式 noip2008 双栈排序 noip2008 传纸条
- 【枚举】[NOIP2008]火柴棒等式
- NOIP2008 火柴棒等式
- 【CS 1168】火柴棒等式 2008年NOIP全国联赛提高组
- NOIP2008解题报告(C/C++)(笨小猴)(火柴棒等式)(传纸条)(双栈排序)
- 【NOIP2008】T2 火柴棒等式 题解
- luogu1149【2008提高】火柴棒等式(模拟)
- NOIP2008 火柴棒等式
- NOIP 2008 解题报告(笨小猴,火柴棒等式,传纸条,双栈排序)