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

Envío 6591

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

  • Autor: bryancalisto
  • Fecha: 2022-08-18 01:25:02 UTC (Hace más de 1 año)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.006 s 11 KBi
#2
Incorrecto
0.006 s 9 KBi
#3
Incorrecto
0.004 s 20 KBi
#4
Incorrecto
0.006 s 17 KBi
#5
Tiempo límite excedido
1.098 s 1 KBi
#6
Tiempo límite excedido
1.074 s 5 KBi
#7
Tiempo límite excedido
1.072 s 2 KBi
#8
Tiempo límite excedido
1.1 s 4 KBi
#9
Tiempo límite excedido
1.094 s 4 KBi
#10
Tiempo límite excedido
1.095 s 1 KBi
#11
Tiempo límite excedido
1.069 s 1 KBi
#12
Tiempo límite excedido
1.07 s 65 KBi
#13
Tiempo límite excedido
1.078 s 5 KBi
#14
Tiempo límite excedido
1.097 s 1 KBi
#15
Tiempo límite excedido
1.069 s 4 KBi
Puntos totales: 0 / 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);
  }

  vector<int> tbl = vector<int>(10000);
  cin >> M;
  while (M > 0)
  {
    int cantidad;
    cin >> cantidad;
    tbl[0] = 1;

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

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

  return 0;
}