█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6805

Problema 0xcb - Contar maneras de formar una cantidad con monedas

  • Autor: danidiaztech
  • Fecha: 2022-12-09 01:46:10 UTC (Hace alrededor de 2 meses)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.012 s 9 KBi
#2
Incorrecto
0.01 s 18 KBi
#3
Correcto
0.005 s 20 KBi
#4
Correcto
0.006 s 8 KBi
#5
Correcto
0.008 s 14 KBi
#6
Correcto
0.006 s 12 KBi
#7
Correcto
0.01 s 6 KBi
#8
Correcto
0.007 s 3 KBi
#9
Correcto
0.293 s 15 KBi
#10
Incorrecto
0.303 s 2 KBi
#11
Incorrecto
0.294 s 6 KBi
#12
Incorrecto
0.155 s 7 KBi
#13
Correcto
0.171 s 10 KBi
#14
Incorrecto
0.228 s 6 KBi
#15
Incorrecto
0.018 s 2 KBi
Puntos totales: 60 / 100

Código

// Made by Daniel Diaz (@Danidiaztech)
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define forn(i, n) for (int i = 0; i < n; i++) // for in range in python
#define FOR(i, a, b) for (int i = a; i < b; i++) // for in range in python
#define int long long int
#define double long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair

typedef pair<int, int> pii;

const int MAX = 1e5;
const int MIN = -MAX;
const int INF = LLONG_MAX;
const int MINF = LLONG_MIN;
const int MOD = 1e9 + 7;

// Up to limit 10000
int dp[MAX + 10];
int32_t main() {
  fastInp;
  #if LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  int n; cin >> n;
  int a[n];
  for (int i =0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  dp[0] = 1;
  for (int i = 0; i < n ;i++){
    for (int j= 1; j <= MAX + 1; j++){
        if (j - a[i] >=  0)
          dp[j] += dp[j - a[i]];
    }
  }
  int q; cin >> q;
  while(q--){
    int c; cin >> c;
    cout << dp[c] << endl;
  }
}