naquo

OIA 2014 - Nivel 3 Problema 2 - "Juego de televisión"

Jul 29th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "television.h"
  3.  
  4. int es_ganador[3000] = {0};
  5. int cant_alfombras;
  6. int cant_salidas;
  7. int cant_pasos;
  8. /* 0: Acierto, 1: error, 2: Valor del cupon */
  9. int* grafo[3];
  10. int premio_maximo = 0;
  11. int caminos_maximos = 0;
  12.  
  13. void TV( int C, int S, int M, int acierto[], int error[],int cupon[],int fin[], int * ng, int * maxp, int * nmaxp )
  14. {
  15.     cant_alfombras = C;
  16.     cant_salidas = S;
  17.     cant_pasos = M;
  18.     grafo[0] = acierto;
  19.     grafo[1] = error;
  20.     grafo[2] = cupon;
  21.     int i;
  22.     for(i = 0; i<S; i++)
  23.         es_ganador[fin[i] - 1] = 1;
  24.     // Aqui debe programar la solucion al problema.
  25.     *ng    = cantidad_caminos(1, 0, 0) % 10000007; // Para devolver ng
  26.     *maxp  = premio_maximo;            // Para devolver maxp
  27.     *nmaxp = caminos_maximos % 10000007; // Para devolver nmaxp
  28. }
  29.  
  30. int cantidad_caminos(int nodo, int pasos, int premio_acumulado) {
  31.     if(pasos == cant_pasos) {
  32.         if(es_ganador[nodo - 1]) {
  33.             //emitir_premio(premio_acumulado + grafo[2][nodo - 1]);
  34.             emitir_premio(premio_acumulado);
  35.             return 1;
  36.         }
  37.         else {
  38.             return 0;
  39.         }
  40.     } else {
  41.         return cantidad_caminos(grafo[0][nodo - 1], pasos + 1, premio_acumulado + grafo[2][nodo - 1])
  42.              + cantidad_caminos(grafo[1][nodo - 1], pasos + 1, premio_acumulado);
  43.     }
  44. }
  45.  
  46. int emitir_premio(int premio) {
  47.     if(premio > premio_maximo) {
  48.       premio_maximo = premio;
  49.       caminos_maximos = 1;
  50.     } else if(premio == premio_maximo) {
  51.       caminos_maximos++;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment