4.25日網易雷火筆試

題目:神奇的數字

參考:

  1. 2020/4/25 網易雷火服務端代碼
  2. 網易雷火遊戲後臺開發筆試

代碼:(通過20%)

import java.util.*;

public class Main_1 {

    public static int N;
    public static int S;
    public static int X;
    public static int ans = 0;
    public static int tmp;

    public static void dfs(int index, int mul, int sum)
    {
        if(index >= 3)
        {
            if(mul % X != 0)
            {
                return;
            }
        }
        if(sum > S)
        {
            return;
        }
        if(index >= N)
        {
            if(sum == S)
            {
                ans = (ans + 1) % 1000009;
            }
            return;
        }
        for(int i = 0; i < 10; i++)
        {
            tmp = (mul % 100) * 10 + i;
            dfs(index + 1, tmp, sum + i);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt())
        {
            N = sc.nextInt();
            S = sc.nextInt();
            X = sc.nextInt();            
            dfs(0, 0, 0);
            System.out.println(ans);
            ans = 0; // 清零
        }
    }
}

// 輸入:
// 4 3 3
// 輸出:
// 6
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章