Codeforces Round #693

A

import sys
import os
from sys import stdin, stdout

def main():
    t = int(stdin.readline())
    for _ in range(t):
        w,h,n= list(map(int, stdin.readline().split()))
        a=0
        b=0
        while(w%2==0):
            w=w//2
            a=a+1
        while(h%2==0):
            h=h//2
            b=b+1
        ans=2**(a+b)
        if ans>=n:
            stdout.write("YES\n")
        else:
            stdout.write("NO\n")


main()

B

import sys
import os
from sys import stdin, stdout

def main():
    t = int(stdin.readline())
    for _ in range(t):
        n = int(stdin.readline())
        a= list(map(int, stdin.readline().split()))
        x,y=0,0
        for i in a:
            if i==1:
                x=x+1
            else:
                y=y+1
        if x%2==0 and x>0:
            stdout.write("YES\n")
        elif x%2==0 and y%2==0:
            stdout.write("YES\n")
        else:
            stdout.write("NO\n")

main()

C

自己通过的代码,从前向后,并且重新开辟了一个数组

import sys
import os
from sys import stdin, stdout

def main():
    t = int(stdin.readline())
    for _ in range(t):
        n=int(stdin.readline())
        arr= list(map(int, stdin.readline().split()))
        a=[0]
        a=a+arr
        b=list(a[:])
        maxx=-1
        for i in range(1,n+1):
            if(a[i]+i>n):
                maxx=max(maxx,b[i])
            else:
                b[i+a[i]]=max(b[i+a[i]],a[i+a[i]]+b[i])

        print(maxx)

main()

别人通过的,简单又明了,最后利用list的特性

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1,-1,-1):
        if i + a[i] < n:
            a[i] = a[i] + a[i+a[i]]
    print(max(a))