Cod sursa(job #2306928)

Utilizator anamariatoaderAna Toader anamariatoader Data 23 decembrie 2018 11:44:41
Problema Pavare2 Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.53 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("pavare2.in");
ofstream fout("pavare2.out");
int N,n,m,i,j;
bool ok;
unsigned long long a[105][105],b[105][105],k,l;
void tipar(int n){
    for(int i=1;i<=n;i++)
        fout<<ok;
}
int main()
{
    fin>>N>>n>>m>>k;
    a[0][0]=b[0][0]=1;
    for(i=1;i<=N;i++){
        for(j=1;j<=n && j<=i;j++){
            a[i][j]=b[i-j][0];
            a[i][0]+=a[i][j];
        }
        for(j=1;j<=m && j<=i;j++){
            b[i][j]=a[i-j][0];
            b[i][0]+=b[i][j];
        }
    }
    fout<<a[N][0]+b[N][0]<<'\n';
    ok=0;
    l=N;
    while(l!=0){
        if(ok==0){
            if(a[l][0]<k){
                k-=a[l][0];
                ok=1;
            }
            else{
                for(j=n;j>=1;j--)
                    if(k>a[l][j])
                        k-=a[l][j];
                    else{
                        tipar(j);
                        l-=j;
                        ok=1;
                        break;
                    }
            }
        }
        else{
            if(b[l][0]<k){
                k-=b[l][0];
                ok=0;
            }
            else{
                for(j=1;j<=m;j++)
                    if(k>b[l][j])
                        k-=b[l][j];
                    else{
                        tipar(j);
                        l-=j;
                        ok=0;
                        break;
                    }
            }
        }
    }
    return 0;
}