Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define inf 100000
- int main() {
- int coinnumbers,a;
- vector <int> coins;
- int money ;
- scanf("%d",&money);
- scanf("%d",&coinnumbers);
- int mat[coinnumbers][money+1];
- for ( int i = 0 ; i < coinnumbers ; i++) {
- scanf("%d",&a);
- coins.push_back(a);
- }
- for ( int i = 0 ; i < coinnumbers ; i++) {
- for ( int j = 0 ; j < money+1 ; j++) {
- mat[i][j] = inf ;
- }
- }
- for ( int i = 0 ; i < coinnumbers ; i++) {
- mat[i][0] = 0 ;
- }
- for ( int i = 0 ; i < coinnumbers ; i++) {
- for ( int j = 0 ; j < money+1 ; j++) {
- if ( j - coins[i] < 0) {
- if ( i - 1 >= 0 ) mat[i][j] = mat[i-1][j];
- }
- else {
- if ( i - 1 >= 0 ) mat[i][j] = min(mat[i-1][j],mat[i][j-coins[i]]+1);
- else mat[i][j] = mat[i][j-coins[i]]+1;
- }
- }
- }
- for ( int i = 0 ; i < coinnumbers ; i++) {
- for ( int j = 0 ; j < money+1 ; j++) {
- cout << mat[i][j] << " ";
- }
- cout << endl;
- }
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement