暴力+剪枝……我还想再优化点,试着提交一下居然过了

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#pragma warning(disable:4996)
int N, M, L, A[105], lie, lie_wolf, lie2, is_wolf[105];
vector<int> ans, relate[105];void dfs(int index) {if (lie > L) return;if (ans.size() == M) {lie2 = lie_wolf = 0;for (int i = 1; i <= N; ++i) {if ((A[i] > 0 && is_wolf[abs(A[i])] == 1) ||(A[i] < 0 && is_wolf[abs(A[i])] == 0)) {++lie2;if (is_wolf[i]) ++lie_wolf;}}if (lie_wolf > 0 && lie_wolf < M && lie2 == L) {for (int i = 0; i < M; ++i) {if (i != M - 1) printf("%d ", ans[i]);else printf("%d\n", ans[i]);}exit(0);}return;}for (int k = index; k > 0; --k) {if (k + ans.size() < M) break;ans.push_back(k); is_wolf[k] = 1;for (auto x : relate[k])lie += x > 0 ? 1 : 0;dfs(k - 1);ans.pop_back(); is_wolf[k] = 0;for (auto x : relate[k])lie += x > 0 ? -1 : 0;}}
int main() {scanf("%d %d %d", &N, &M, &L);for (int i = 1; i <= N; ++i) {scanf("%d", A + i);int f = A[i] > 0 ? 1 : -1;relate[f*A[i]].push_back(f*i);//+代表认为是人,-狼}dfs(N);printf("No Solution\n");
}

PAT 1022. Werewolf (35)相关推荐

  1. PAT TOP 1022. Werewolf (35)

    问题描述: 1022. Werewolf (35) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Werewol ...

  2. 1022 Werewolf (35 分)(C++)

    PAT顶级题解目录​​​​​​​ Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the ...

  3. PAT Top 1022 Werewolf (35)

    PAT Top 1022 Werewolf (35) 题目描述 Input Specification: Output Specification: Sample Input: Sample Outp ...

  4. T1022 Werewolf (35 point(s))

    T1022 Werewolf (35 point(s)) 文章目录 T1022 Werewolf (35 point(s)) 题干 Input Specification: Output Specif ...

  5. pat顶级1022 Werewolf (35 point(s))

    欢迎访问我的pat顶级题解目录哦 https://blog.csdn.net/richenyunqi/article/details/86751676 题目描述 算法设计 这道题是pat甲级1148 ...

  6. PAT——1022. D进制的A+B

    输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数. 输入格式: 输入在一行中依次给出3个整数A.B和D. 输出格式: 输出A+B的D ...

  7. PAT 1148 Werewolf – Simple Version – 甲级

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  8. PAT_A1148#Werewolf - Simple Version

    Source: PAT A1148 Werewolf - Simple Version (20 分) Description: Werewolf(狼人杀) is a game in which the ...

  9. 【PTA Advanced】1148 Werewolf - Simple Version(C++)

    目录 题目 Input Specification: Output Specification: Sample Input 1: Sample Output 1: Sample Input 2: Sa ...

最新文章

  1. (C++)数组作为函数参数
  2. Serval and Bus
  3. hdu 4714 树+DFS
  4. 数据结构-链表2-链式存储
  5. bash中正则表达式
  6. 关于配置tomcat多版本同eclipse的配置问题
  7. mysql 全局排序 取第n条_MySQL分组排序取前N条记录 以及 生成自动数字序列 的SQL...
  8. 【转】伪O2O已死?2016年实体零售将迎来真正的O2O
  9. 2022年计算机软件水平考试数据库系统工程师(中级)练习题及答案
  10. html及css经典面试题
  11. mysql 生日_MySQL数据库之MySql查询生日的两种方式
  12. 神经网络计算棒有什么用,神经网络计算棒怎么用
  13. 2019字节跳动实习面试
  14. 西门子300 PLC 功能块及背景数据块的说明
  15. 数据仓库主题设计及元数据设计
  16. 数据分析 第七讲 pandas练习 数据的合并、分组聚合、时间序列、pandas绘图
  17. iPhone、iPad、iPadMini界面设计标准
  18. 马云天价请不动的中国顶级黑客
  19. 复制粘贴出现乱码的解决
  20. cmake教程5-macro宏定义以及传递参数给源文件

热门文章

  1. 深入扒一扒 NumPy 中文网《防脱发指南》,糟糕被圈粉了!
  2. 来自海拉鲁的社区常见问题汇总(不定时更新)
  3. Windows 10使用 Packer 和 VMware Player 自动构建CentOS 8虚拟机镜像
  4. Android RatingBar控件
  5. scipy 概率 泊松分布_概率论中常见分布总结以及python的scipy库使用:两点分布、二项分布、几何分布、泊松分布、均匀分布、指数分布、正态分布......
  6. surface pro 4的键盘盖如何直接使用功能键F1-F12
  7. 设置background-color背景色为全透明
  8. UNIX时间戳 转换标准时间格式【JS】
  9. 鼠标 DPI与CPI
  10. Linux下的编程实战【转】