一本通1211 全排列应用
作者:互联网
[http://ybt.ssoier.cn:8088/problem_show.php?pid=1211]()
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <map> #include <queue> #include <set> #include <iterator> #include <vector> #define maxn 10000005 typedef long long ll; using namespace std; int N,k; int a[maxn]; set<int> s; bool dfs(int n,ll sum,int num){ if(num==N){ sum=sum+n; //cout<<" sum "<<sum<<endl; s.insert(abs(sum)); return true; }else{ sum=sum+n; num=num+1;//num++不行 dfs(a[num],sum,num); dfs(-a[num],sum,num); } } int main(){ cin>>N>>k; for(int i=1;i<=N;i++){ cin>>a[i]; } dfs(a[1],0,1); dfs(-a[1],0,1); int f=1; set<int>::iterator it; for(it=s.begin();it!=s.end();it++){ if((*it)%k==0){ cout<<"YES"; f=0; break; } } if(f==1){ cout<<"NO"; } return 0; }
标签:num,排列,set,int,sum,dfs,1211,一本,include 来源: https://www.cnblogs.com/lwx11111/p/15924701.html