swjtuoj 2383 Music Problem

来源:互联网 发布:苹果蜂窝移动网络位置 编辑:程序博客网 时间:2024/06/06 01:56

题目链接:Music Problem

题目大意:给你一堆正整数,问能不能从中间找出来一些数他们的和对3600求余为零

题目思路:模拟01背包,暴力写一下就好

#include <bits/stdc++.h>using namespace std;int t,n,a[100005];void solve(){    scanf("%d",&n);    for(int i = 1; i <= n; i++)        scanf("%d",&a[i]);    a[1] %= 3600;    int dp[4005] = {0};    vector<int>v;    dp[a[1]] = 1;    if(dp[0]){        cout<<"YES"<<endl;        return ;    }    v.push_back(a[1]);    for(int i = 2; i <= n; i++){        int xx = a[i]%3600;        int si = v.size();        if(dp[xx] == 0){            dp[xx] = 1;            v.push_back(xx);        }        if(!xx){            cout<<"YES"<<endl;            return ;        }        for(int j = 0;j < si;j++){            int tmp = (v[j]+a[i])%3600;            if(dp[tmp]) continue;            dp[tmp] = 1;            v.push_back(tmp);        }        if(dp[0]){            cout<<"YES"<<endl;            return ;        }    }    cout<<"NO"<<endl;}int main(){    ios::sync_with_stdio(false);    scanf("%d",&t);    while(t--){        solve();    }    return 0;}
原创粉丝点击