#include <iostream>
using namespace std;
long long suma = 0;
int obrazy[30];
bool obliczLiczbeObrazow(int w, int h, int index) {
if(index <0){
if(h*w != 0)
return 0;
return 1;
}
if(obrazy[index]<=h){
if(obrazy[index]<=w){
long long iloscx = w/obrazy[index];
long long iloscy = h/obrazy[index];
suma+=iloscx * iloscy;
return obliczLiczbeObrazow(w-iloscx*obrazy[index],iloscy*obrazy[index],index -1)
&& obliczLiczbeObrazow(w,h-iloscy*obrazy[index],index -1);
} else
return obliczLiczbeObrazow(w,h,index-1);
}
else
return obliczLiczbeObrazow(w,h,index - 1);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int szerokoscSciany, wysokoscSciany, n;
cin >> wysokoscSciany >> szerokoscSciany>>n;
for (int i = 0; i < n; ++i)
cin >> obrazy[i];
if(!obliczLiczbeObrazow(szerokoscSciany,wysokoscSciany,n-1))
cout<<-1;
else
cout<<suma;
return 0;
}
1 2 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 | #include <iostream> using namespace std; long long suma = 0; int obrazy[30]; bool obliczLiczbeObrazow(int w, int h, int index) { if(index <0){ if(h*w != 0) return 0; return 1; } if(obrazy[index]<=h){ if(obrazy[index]<=w){ long long iloscx = w/obrazy[index]; long long iloscy = h/obrazy[index]; suma+=iloscx * iloscy; return obliczLiczbeObrazow(w-iloscx*obrazy[index],iloscy*obrazy[index],index -1) && obliczLiczbeObrazow(w,h-iloscy*obrazy[index],index -1); } else return obliczLiczbeObrazow(w,h,index-1); } else return obliczLiczbeObrazow(w,h,index - 1); } int main() { cin.tie(0); ios::sync_with_stdio(0); int szerokoscSciany, wysokoscSciany, n; cin >> wysokoscSciany >> szerokoscSciany>>n; for (int i = 0; i < n; ++i) cin >> obrazy[i]; if(!obliczLiczbeObrazow(szerokoscSciany,wysokoscSciany,n-1)) cout<<-1; else cout<<suma; return 0; } |
English