leetcode-935-骑士拨号器-knightDialer
生活随笔
收集整理的這篇文章主要介紹了
leetcode-935-骑士拨号器-knightDialer
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
leetcode-935-騎士撥號器-knightDialer
package com.ant.learning.part1;import java.util.Arrays; import java.util.HashMap; import java.util.List;/**** 騎士撥號 leetcode.935 ::DP* Created by wolf 2018/11/9*/public class knightDialer {public static void main(String[] args) {System.out.println( knightDialer(2));}public static long knightDialer(Integer n){long mod = (long) (Math.pow(10,9) + 7);int[][] willTobe = {{4,6},{6,8},{7,9},{4,8},{3,9,0},{},{1,7,0},{2,6},{1,3},{2,4}};int[] res = {1,1,1,1,1,1,1,1,1,1};if(n==1)return 10;while ( n>1 ){int[] new_ = {0,0,0,0,0,0,0,0,0,0};for(int count=0;count<10;count++){for(int choice:willTobe[count]){new_[choice]+=res[count];}}res=new_;n--;}return sum(res)%mod;}private static long sum(int[] nums){long res=0;for (long num:nums){res+=num;}return res;} }?
posted @ 2018-11-09 15:08 NHZ-M 閱讀(...) 評論(...) 編輯 收藏總結
以上是生活随笔為你收集整理的leetcode-935-骑士拨号器-knightDialer的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何通过看电影学英语来源
- 下一篇: 关于Android开发中图片的三级缓存机