fork download
  1. #include <stdio.h>
  2.  
  3. int N, price[1001][3];
  4. int dp[1001][3];
  5.  
  6. void read();
  7. int min(int a, int b);
  8.  
  9. int main(void)
  10. {
  11. int i = 0;
  12. int res = 0;
  13.  
  14. read();
  15.  
  16. dp[1][0] = price[1][0];
  17. dp[1][1] = price[1][1];
  18. dp[1][2] = price[1][2];
  19.  
  20. for(i = 2; i <= N; ++i)
  21. {
  22. dp[i][0] = price[i][0] + min(dp[i - 1][1], dp[i - 1][2]);
  23. dp[i][1] = price[i][1] + min(dp[i - 1][0], dp[i - 1][2]);
  24. dp[i][2] = price[i][2] + min(dp[i - 1][0], dp[i - 1][1]);
  25. }
  26.  
  27. res = min(min(dp[N][0], dp[N][1]), dp[N][2]);
  28. printf("%d\n", res);
  29.  
  30. return 0;
  31. }
  32.  
  33. void read()
  34. {
  35. int i = 0;
  36.  
  37. scanf("%d", &N);
  38. for(i = 1; i <= N; ++i)
  39. {
  40. scanf("%d", &price[i][0]);
  41. scanf("%d", &price[i][1]);
  42. scanf("%d", &price[i][2]);
  43. }
  44. }
  45.  
  46. int min(int a, int b)
  47. {
  48. return (a > b) ? b : a;
  49. }
Success #stdin #stdout 0s 4392KB
stdin
3
26 40 83
49 60 57
13 89 99
stdout
96