洛谷 CF1743APassword 题解
创始人
2024-04-28 23:24:12
0

洛谷 CF1743APassword 题解

  • 题目
    • 链接
    • 字面描述
  • Password
    • 题面翻译
    • 题目描述
    • 输入格式
    • 输出格式
    • 样例 #1
      • 样例输入 #1
      • 样例输出 #1
    • 提示
  • 思路
  • 代码实现

题目

链接

https://www.luogu.com.cn/problem/CF1743A

字面描述

Password

题面翻译

已知一个长度为四的,只包含字符 0,1,2,…,90,1,2,\dots ,90,1,2,…,9 的字符串中不会出现哪些字符,求可能的字符串的数量。

题目描述

Monocarp has forgotten the password to his mobile phone. The password consists of $ 4 $ digits from $ 0 $ to $ 9 $ (note that it can start with the digit $ 0 $ ).

Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.

You have to calculate the number of different sequences of $ 4 $ digits that could be the password for Monocarp’s mobile phone (i. e. these sequences should meet all constraints on Monocarp’s password).

输入格式

The first line contains a single integer $ t $ ( $ 1 \le t \le 200 $ ) — the number of testcases.

The first line of each testcase contains a single integer $ n $ ( $ 1 \le n \le 8 $ ) — the number of digits for which Monocarp remembers that they were not used in the password.

The second line contains $ n $ different integers $ a_1, a_2, \dots a_n $ ( $ 0 \le a_i \le 9 $ ) representing the digits that were not used in the password. Note that the digits $ a_1, a_2, \dots, a_n $ are given in ascending order.

输出格式

For each testcase, print one integer — the number of different $ 4 $ -digit sequences that meet the constraints.

样例 #1

样例输入 #1

2
8
0 1 2 4 5 6 8 9
1
8

样例输出 #1

6
216

提示

In the first example, all possible passwords are: “3377”, “3737”, “3773”, “7337”, “7373”, “7733”.

思路

很简单,就是枚举

代码实现

#include
using namespace std;const int maxn=20;
int t,n,x,ans;
int cnt[maxn];
int main(){scanf("%d",&t);while(t--){memset(cnt,0,sizeof(cnt));ans=0;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&x);cnt[x]=-1;}for(int i=0;i<=9;i++){if(cnt[i]==-1)continue;++cnt[i];for(int j=0;j<=9;j++){if(cnt[j]==-1)continue;++cnt[j];for(int k=0;k<=9;k++){if(cnt[k]==-1)continue;++cnt[k];for(int l=0;l<=9;l++){if(cnt[l]==-1)continue;++cnt[l];bool flag=true;int tot=0;for(int p=0;p<=9;p++){if(cnt[p]==0)continue;else if(cnt[p]==-1)continue;else if(cnt[p]==2)++tot;else {flag=false;break;}}--cnt[l];if(!flag||tot!=2)continue;//printf("go\n");++ans;}--cnt[k];}--cnt[j];}--cnt[i];}printf("%d\n",ans);}return 0;
} 

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
【Ctfer训练计划】——(三... 作者名:Demo不是emo  主页面链接:主页传送门 创作初心ÿ...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
带头循环双向链表来咯!!! 前言:继上文,我们了解了结构最简单的一种链表---单链表那么我们今天就来...