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

Envío 5458

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

  • Autor: bryancalisto
  • Fecha: 2021-12-18 00:09:37 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.001 s 0 KBi
#2
Incorrecto
0.001 s 0 KBi
#3
Correcto
0.005 s 59 KBi
#4
Correcto
0.006 s 8 KBi
#5
Correcto
0.414 s 0 KBi
#6
Tiempo límite excedido
1.068 s 35 KBi
#7
Correcto
0.828 s 0 KBi
#8
Tiempo límite excedido
1.071 s 8 KBi
#9
Tiempo límite excedido
1.051 s 61 KBi
#10
Tiempo límite excedido
1.054 s 8 KBi
#11
Tiempo límite excedido
1.024 s 1 KBi
#12
Tiempo límite excedido
1.064 s 0 KBi
#13
Tiempo límite excedido
1.071 s 2 KBi
#14
Tiempo límite excedido
1.083 s 0 KBi
#15
Tiempo límite excedido
1.062 s 0 KBi
Puntos totales: 34 / 100

Código

#include <bits/stdc++.h>

using namespace std;

int main()
{
  int N;
  vector<int> monedas;
  int M;

  cin >> N;
  for (int i = 0; i < N; i++)
  {
    int mon;
    cin >> mon;
    monedas.push_back(mon);
  }

  cin >> M;

  for (int i = 0; i < M; i++)
  {
    int cantidad;
    cin >> cantidad;
    vector<int> tbl = vector<int>(cantidad + 1);
    tbl[0] = 1;

    for (int j = 0; j < N; j++)
    {
      for (int k = 0; k < tbl.size(); k++)
      {
        if (monedas[j] <= k)
        {
          tbl[k] += tbl[k - monedas[j]];
        }
      }
    }

    cout << tbl[cantidad]<<endl;
  }

  return 0;
}