比赛 顾研NOIP2011模拟赛 评测结果 AAAAAAAAAA
题目名称 项链 最终得分 100
用户昵称 苏轼 运行时间 0.128 s
代码语言 C++ 内存使用 3.15 MiB
提交时间 2012-10-17 20:27:58
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. using namespace std;
  6. int n,w[30]={0};
  7. int answer=0;
  8. void dfs(int x,int num,int ans);
  9. int main()
  10. {
  11. freopen ("necklaced.in","r",stdin);
  12. freopen ("necklaced.out","w",stdout);
  13. cin>>n;
  14. for (int i=0;i<n;i++)
  15. {
  16. string s;
  17. cin>>s;
  18. for (int j=0;j<s.size();j++)
  19. {
  20. w[i]+=1<<(s[j]-'A');
  21. }
  22. }
  23. dfs(0,0,0);
  24. cout<<answer;
  25. return 0;
  26. }
  27. void dfs(int x,int num,int ans)
  28. {
  29. if (x==n)
  30. {
  31. if (ans>answer&&num==0)
  32. answer=ans;
  33. }
  34. else
  35. {
  36. int num1;
  37. num1=num^w[x];
  38. dfs(x+1,num1,ans+1);
  39. dfs(x+1,num,ans);
  40. }
  41. }