P1356 数列的整除性

Archie
记忆化搜索就好

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int m;
int x;
int a[10005];
int n,k;
int f[10005][105];
bool dfs(int no,int re){
    if(f[no][re]!=-1){
        return f[no][re];
    }
    if(no==n+1){
        return re==0;
    }
    return f[no][re]=(dfs(no+1,(re+a[no])%k)|dfs(no+1,(re-a[no]+k)%k));
}
int main(){
    scanf("%d",&m);
    while(m--){
        scanf("%d%d",&n,&k);
        memset(f,-1,sizeof(f));
        for(int i=1;i<=n;++i){
            scanf("%d",&x);
            a[i]=(x%k+k)%k;
        }
        if(dfs(1,0)){
            printf("Divisiblen");
        }else{
            printf("Not divisiblen");
        }
    }
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇