Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "television.h"
- int es_ganador[3000] = {0};
- int cant_alfombras;
- int cant_salidas;
- int cant_pasos;
- /* 0: Acierto, 1: error, 2: Valor del cupon */
- int* grafo[3];
- int premio_maximo = 0;
- int caminos_maximos = 0;
- void TV( int C, int S, int M, int acierto[], int error[],int cupon[],int fin[], int * ng, int * maxp, int * nmaxp )
- {
- cant_alfombras = C;
- cant_salidas = S;
- cant_pasos = M;
- grafo[0] = acierto;
- grafo[1] = error;
- grafo[2] = cupon;
- int i;
- for(i = 0; i<S; i++)
- es_ganador[fin[i] - 1] = 1;
- // Aqui debe programar la solucion al problema.
- *ng = cantidad_caminos(1, 0, 0) % 10000007; // Para devolver ng
- *maxp = premio_maximo; // Para devolver maxp
- *nmaxp = caminos_maximos % 10000007; // Para devolver nmaxp
- }
- int cantidad_caminos(int nodo, int pasos, int premio_acumulado) {
- if(pasos == cant_pasos) {
- if(es_ganador[nodo - 1]) {
- //emitir_premio(premio_acumulado + grafo[2][nodo - 1]);
- emitir_premio(premio_acumulado);
- return 1;
- }
- else {
- return 0;
- }
- } else {
- return cantidad_caminos(grafo[0][nodo - 1], pasos + 1, premio_acumulado + grafo[2][nodo - 1])
- + cantidad_caminos(grafo[1][nodo - 1], pasos + 1, premio_acumulado);
- }
- }
- int emitir_premio(int premio) {
- if(premio > premio_maximo) {
- premio_maximo = premio;
- caminos_maximos = 1;
- } else if(premio == premio_maximo) {
- caminos_maximos++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment