Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int P[100];
- int N,K,S;
- int A[100][50];
- void Olvas()
- {
- ifstream f("dollar.be");
- f>>N>>K;
- for(int i=1;i<=N;i++)
- {
- f>>P[i];
- S+=P[i];
- }
- f.close();
- }
- int Kiir(int x[])
- {
- cout<<"Index: ";
- for(int i=1;i<=N;i++)
- {
- cout.width(4);
- cout<<i<<" ";
- }
- cout<<endl<<"Osszeg:";
- for(int i=1;i<=N;i++)
- {
- cout.width(4);
- cout<<x[i]<<" ";
- }
- cout<<"\nKifizetendo: "<<K<<endl;
- }
- int Fizetheto()
- {
- return 1;
- }
- void fizet()
- {
- for(int i=0;i<=N;i++)
- {
- for(int j=1;j<=12;j++)
- {
- if(Fizetheto())
- A[i][j]=1;
- }
- }
- }
- void Mutat()
- {
- for(int i=0;i<=N;i++)
- {
- for(int j=1;j<=12;j++)
- {
- cout<<A[i][j];
- }
- }
- }
- void Feltolt()
- {
- A[P[1]][1]=1;
- for(int i=2;i<=N;i++)
- {
- for(int x=1;x<=K;x++)
- {
- if(A[x][i-1]==1)
- A[x][i]=1;
- else
- if(x==P[i])
- A[x][i]=1;
- else
- if(x>P[i] && A[x-P[i]][i-1]==1)
- A[x][i]=1;
- }
- }
- }
- void Nyomtat()
- {
- for(int i=1;i<=K;i++)
- {
- cout.width(4);
- cout<<i<<" lej:";
- for(int j=1;j<=N;j++)
- {
- cout.width(4);
- cout<<A[i][j];
- }
- cout<<endl;
- }
- cout<<endl;
- }
- void Eredmeny()
- {
- if(A[K][N]==0)
- cout<<"nem kifizetheto az osszeg!!!!!!!!!!!!";
- else
- {
- int x=K, i=N;
- while(A[x][i]>0)
- {
- while(i>=1 && A[x][i]==A[x][i-1])
- i--;
- cout<<P[i]<<" ";
- x=x-P[i];
- i--;
- }
- }
- }
- int main()
- {
- Olvas();
- Kiir(P);
- if(K>S)
- {
- cout<<"Nem fizetheto ki az oszzeg!!!!!!!!!";
- return 0;
- }
- Feltolt();
- Nyomtat();
- Eredmeny();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement