Dice

시간 제한2초메모리 제한1024 MB

요약
주어진 굴림마다 n개의 f면체 주사위를 굴려 나온 눈의 합에 m을 더해 보고된 합을 만들 수 있는지 판정한다.
난이도

쉬움10점 중 3점

유형
동적 계획법, 수학, 구현
정답자
아직 제출이 없습니다

문제

Khodislav is playing a tabletop role-playing game. He has finally chosen his weapons to deal with a monster and casts the crushing strike. To do this, he rolls dice, calculates the sum of numbers on their faces, and says it aloud to the game master.

Rolling a group of identical dice is characterized by three numbers nn, ff, and mm, where nn is the number of the dice, ff is the number of faces on each die, and mm is the modifier. The faces carry all numbers from 11 through ff, and each and any face can be rolled; all rolls are independent. For instance, if n=3n = 3, f=8f = 8, m=5m = 5, to define the sum, the player must roll three eight-faced dice, sum up the results, and add five: this is usually written as 3d8+53d8 + 5.

The game master wants to check if Khodislav could get the sum he has reported after rolling the dice.

입력

The first line of the input file contains a single integer BB --- the number of strikes (1≤B≤1051 \le B \le 10^5) cast by Khodislav. The following lines describe the strikes, one per line. First comes an integer SS --- the sum reported by Khodislav. It is followed by three integers: nn, ff and mm describing the group of dice (1≤S≤3001 \le S \le 300, 1≤n≤101 \le n \le 10, 2≤f≤202 \le f \le 20, 0≤m≤100 \le m \le 10).

출력

For each strike in a separate line, in the same order as in the input file, print YES, if the sum was achievable, and NO otherwise.

예제1

  1. 예제 1

    입력
    5
    3 1 6 0
    1 1 8 1
    16 1 12 3
    1 2 4 0
    42 3 20 1
    
    예상 출력
    YES
    NO
    NO
    NO
    YES