Description
有一个未完成的等式1 2 3 4 5 6 7 8 9=N空格内(1前面没有空格)可以填入+,-,也可以不填。
编程找出输入某个整数 N 后使等式成立的所有方案的总数。保证有解。
Input
该题含有多组测试数据,每组数据为一行,仅一个整数N。
Output
Sample Input
108
Sample Output
15
Source
oibh
KEY:这题我是没想出什么好的方法了……就用了枚举……把所有情况都给出了……
Source:

#include<iostream>
using namespace std;


int op[10]=...{0,0,0,0,0,0,0,0,0,3};

int a[]=...{0,1,2,3,4,5,6,7,8,9};
int N;

int judge()

...{
int i,j,k=0,t=a[1];
int b[10];
for(i=1,j=2;i<=9;i++,j++)

...{
if(op[i]==0)

...{
t=t*10+a[j];
}
else

...{
b[++k]=t;
t=a[j];
}
}
t=b[1];
i=1;
for(j=2;j<=k;j++)

...{
while(op[i]==0) i++;
if(op[i]==1)

...{
t=t-b[j];
i++;
}
else

...{
t=t+b[j];
i++;
}
}
if(t==N) return 1;
else return 0;
}

int main()

...{
while(cin>>N)

...{
int count=0;
for(op[1]=0;op[1]<=2;op[1]++)
for(op[2]=0;op[2]<=2;op[2]++)
for(op[3]=0;op[3]<=2;op[3]++)
for(op[4]=0;op[4]<=2;op[4]++)
for(op[5]=0;op[5]<=2;op[5]++)
for(op[6]=0;op[6]<=2;op[6]++)
for(op[7]=0;op[7]<=2;op[7]++)
for(op[8]=0;op[8]<=2;op[8]++)

...{
if(judge()) count++;
}
cout<<count<<endl;
}
return 0;
}













