标签:vat vector mod class pre bsp int private public
1 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 2 #define _rep(i,a,b) for(int i = (a);i <= (b);i ++) 3 typedef long long int ll; 4 5 class Solution 6 { 7 private: 8 vector<vector<int>> dialList {{4,6},{6,8},{7,9},{4,8},{0,3,9},{},{0,1,7},{2,6},{1,3},{2,4}}; 9 const int MOD = 1000000007; 10 public: 11 int knightDialer(int N) 12 { 13 vector<ll> dp (11,1); 14 int flag = 1; 15 while(-- N) 16 { 17 vector<ll> tmp = dp; 18 if(!flag) 19 { 20 _for(i,0,10) 21 dp[i] = 0; 22 } 23 _for(i,0,10) 24 { 25 for(auto d:dialList[i]) 26 dp[d] = (dp[d]+tmp[i]) % MOD; 27 } 28 if(flag) 29 { 30 _for(i,0,10) 31 { 32 dp[i] --; 33 flag = 0; 34 } 35 } 36 } 37 int result = 0; 38 _for(i,0,10) 39 { 40 result = (result+dp[i]) % MOD; 41 } 42 return result; 43 } 44 };
Leetcode-935 knight-dialer(骑士拨号器)
标签:vat vector mod class pre bsp int private public
原文地址:https://www.cnblogs.com/Asurudo/p/9917070.html