
原题链接
https://www.luogu.com.cn/problem/P1010
解题思路
本蒟蒻来发一波题解,没多少技巧,就是打表。
参考代码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 
 | #include<iostream>#include<cmath>
 #define for(i,a,b) for(int i=a;i<=b;i++)
 using namespace std;
 int n,mega[111];
 string open[15];
 bool odd;
 void even()
 {
 if(n%2==0)return;
 odd=1;
 n-=1;
 return;
 }
 int main()
 {
 cin>>n;
 even();
 for(i,1,14)mega[i]=pow(2,i);
 
 open[1]="2(0)";open[2]="2";open[3]="2+2(0)";open[4]="2(2)";
 open[5]="2(2)+2(0)";open[6]="2(2)+2";open[7]="2(2)+2+2(0)";
 open[8]="2(2+2(0))";open[9]="2(2+2(0))+2(0)";open[10]="2(2+2(0))+2";
 open[11]="2(2+2(0))+2+2(0)";open[12]="2(2+2(0))+2(2)";
 open[13]="2(2+2(0))+2(2)+2(0)";open[14]="2(2+2(0))+2(2)+2";
 
 for(x,0,14)
 for(y,x,14)
 for(z,y,14)
 for(i,z,14)
 for(j,i,14)
 for(k,j,14)
 for(l,k,14)
 {
 if(mega[i]+mega[j]+mega[k]+mega[l]+mega[x]+mega[y]+mega[z]==n)
 {
 if(l&&l!=1)cout<<"2("<<open[l]<<')';
 if(l==1)cout<<"+2";
 if(k&&k!=1)cout<<'+'<<"2("<<open[k]<<')';
 if(k==1)cout<<"+2";
 if(j&&j!=1)cout<<'+'<<"2("<<open[j]<<')';
 if(j==1)cout<<"+2";
 if(i&&i!=1)cout<<'+'<<"2("<<open[i]<<')';
 if(i==1)cout<<"+2";
 if(z&&z!=1)cout<<'+'<<"2("<<open[z]<<')';
 if(z==1)cout<<"+2";
 if(y&&y!=1)cout<<'+'<<"2("<<open[y]<<')';
 if(y==1)cout<<"+2";
 if(x&&x!=1)cout<<'+'<<"2("<<open[x]<<')';
 if(x==1)cout<<"+2";
 if(odd)cout<<"+2(0)";
 return 0;
 }
 }
 }
 
 |