Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BKT
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <cmath>
- using namespace std;
- ifstream f("graf.txt");
- int x[100],n;
- void citire(int &n)
- {
- cin>>n;
- }
- int valid(int k)
- {
- return 1;
- }
- int sol(int k)
- {
- return k==n;
- }
- void tipar(int k)
- {
- if(k==n)
- {
- int s=0;
- for(int i=1;i<=k;i++)
- if(x[i]==0)
- s=s-i*i;
- else
- s=s+i*i;
- if(s==n)
- {
- for(int i=1;i<=n;i++)
- if(i<n)
- {
- if(x[i]==0)
- cout << "-"<<i*i;
- else
- cout << "+"<<i*i;
- }
- else
- {
- if(x[n]==0)
- cout << "-"<<i*i;
- else
- cout << "+"<<i*i;
- }
- cout <<endl;
- }
- }
- }
- void BKT()
- {
- int k=1;
- x[k]=-1;
- while(k)
- if(x[k]<1 && k<=n)
- {
- x[k]=x[k]+1;
- if(valid(k))
- if(sol(k))
- tipar(k);
- else
- {
- k++;
- x[k]=-1;}}
- else
- k--;
- }
- int main()
- {
- citire(n);
- BKT();
- f.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement