903A - Hungry Student Problem - CodeForces Solution


greedy implementation *900

Please click on ads to support us..

Python Code:

def get(x) -> str:
    if can_eat(x):
        return "YES"
    else:
        return "NO"


def can_eat(x: int) -> bool:
    if x == 0:
        return True
    if x < 3:
        return False
    if x in [3, 7]:
        return True

    if can_eat(x-3):
        return True
    if can_eat(x-7):
        return True

    return False


if __name__ == '__main__':
    n = int(input())

    for i in range(n):
        x = int(input())
        print(get(x))
		  					 	 	  			 	 	  		 	

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int l[101];
    l[0] = 1;
    for(int i = 1; i < 101; i++){
        l[i] = 0;
        if(i - 3 >= 0) l[i] |= l[i - 3];
        if(i - 7 >= 0) l[i] |= l[i - 7];
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n;
        scanf("%d", &n);
        printf("%s\n", l[n] ? "YES" : "NO");
    }
}


Comments

Submit
0 Comments
More Questions

Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree