Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int maxVacationDays(int[][] flights, int[][] days) {
- int n = flights.length, k = days[0].length;
- int[][] f = new int[k + 1][n];
- for(int i = 0; i < n; i++)
- {
- f[k][i] = days[i][k - 1]; // base case
- flights[i][i] = 1;
- }
- for(int d = k - 1; d >= 1; d--)
- {
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < n; j++)
- {
- if(flights[i][j] == 0) continue;
- f[d][i] = Math.max(f[d][i], f[d + 1][j] + days[i][d - 1]);
- }
- }
- }
- // for(int[] ff : f) System.out.println(Arrays.toString(ff));
- int max = 0;
- for(int i = 0; i < n; i++)
- {
- if(flights[0][i] == 1) max = Math.max(max, f[1][i]);
- }
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement