洛谷 CF1743APassword 题解

这篇具有很好参考价值的文章主要介绍了洛谷 CF1743APassword 题解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

题目

链接

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

字面描述

Password

题面翻译

已知一个长度为四的,只包含字符 0 , 1 , 2 , … , 9 0,1,2,\dots ,9 0,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”.

思路

很简单,就是枚举文章来源地址https://www.toymoban.com/news/detail-418919.html

代码实现

#include<bits/stdc++.h>
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;
} 

到了这里,关于洛谷 CF1743APassword 题解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • CF1011A Stages 题解

    题目意思: 给你一个长度为 n n n 的字符串 a a a ,在这个字符串中选一个长度为 k k k 的好串(好串标准是啥自己去题目里看吧),问这个好串的最小价值是多少。 思路: 贪心。 首先我们将字符串 a a a 里面的字符进行排序。 因为要最小的价值,所以排好序后的 a a a 的第一个

    2024年02月12日
    浏览(21)
  • CF338D GCD Table 题解

    你有一个长度为 (k) 的数列 (a) , 询问是否存在 (xin[1,n]~~~yin[1,m]) 使得 (forall i~~~ gcd(x,y+i-1)=a_i) 。 我们转换一下可以得到: [forall i ~~left{ begin{matrix}xequiv 0pmod{a_i} \\\\y+i-1equiv 0pmod{a_i}end{matrix}right.] 前面一个 (x) 很好解决,直接 最大公倍数 。 (y) 可以转化一下:

    2024年02月07日
    浏览(26)
  • CF1145G AI Takeover 题解

    人工智能取得了进展。在这一题中,我们考虑的是石头剪刀布游戏。 然而,比赛的前一天晚上有一群人把机器人弄坏了,于是使用一个程序替代。 您需要找到一个策略,使您能够获胜。祝你好运! 为了方便,石头剪刀布分别用三个字符表示: R , P , S 。 本题有 6 个测试点,

    2024年03月26日
    浏览(33)
  • 洛谷P1249题解

    一个正整数一般可以分为几个互不相同的自然数的和,如 3 = 1 + 2 3=1+2 3 = 1 + 2 , 4 = 1 + 3 4=1+3 4 = 1 + 3 , 5 = 1 + 4 = 2 + 3 5=1+4=2+3 5 = 1 + 4 = 2 + 3 , 6 = 1 + 5 = 2 + 4 6=1+5=2+4 6 = 1 + 5 = 2 + 4 。 现在你的任务是将指定的正整数 n n n 分解成若干个互不相同的自然数的和,且使这些自

    2024年02月05日
    浏览(40)
  • 洛谷 P8742题解

    简单版(P2347)传送门 原题传送门 有一道 类似 的题目(P2347),先扯一扯~ 动态规划入门题(01背包 可行性问题 )~ 我们 设 (dp_j) 为能否用砝码称出 (j) 重量 ,1 为 可以 ,0 为 不可以 。 为了转移, (dp_{_{0}} gets 1) , 什么都不放时,重量为 0 ,因此可以称出。 那么 枚举

    2024年02月06日
    浏览(41)
  • 洛谷AT4888 题解-伦伦数

    A positive integer XX is said to be a lunlun number if and only if the following condition is satisfied: In the base ten representation of XX (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 11 . For example, 12341234 , 11 , and 334334 are lunlun numbers, while none of 3141531415 

    2024年02月06日
    浏览(32)
  • CF963B Destruction of a Tree 题解

      洛谷题目链接   这里提供一个较为朴素的 DP 想法。   给定一棵树,节点个数不超过 (2 times 10^5) ,每次可以删掉度数为偶数的点。问最后能不能删完;能删完给出删除方案。   首先可以随便选一个点作为根。   其次,我们考虑在一棵子树的删除情况,我们令

    2024年02月08日
    浏览(27)
  • CF1178F1 Short Colorful Strip 题解

    题目描述 这是F题的第一个子任务。F1和F2的区别仅在对于m和时间的限制上 有n+1种颜色标号从0到n,我们有一条全部染成颜色0的长为m的纸带。 Alice拿着刷子通过以下的过程来给纸带染色: 我们按照从1到n的顺序进行染色,进行每次染色时,我们选取一个区间[ai,bi],0=aibi=m,并

    2024年02月01日
    浏览(26)
  • 洛谷 P1336 最佳课题选择 题解

    题目链接 状态:考虑 (f_{i,j}) 表示前 (i) 种论文里面,一共写了 (j) 篇,的最少花费时间。 转移策略:我们一次考虑每一种论文写多少篇。假设写 (k) 篇, (k in [0,j] cap mathbb{Z}) ,有转移方程: [f_{i,j} = min(f_{i-1,j-k} + text{cost}(i,k)), k in [0,j] cap mathbb{Z}] 其中 [text{

    2024年02月14日
    浏览(25)
  • 洛谷 U123017 机器人题解

    机器人会按照输入的指令进行移动,命令包括’E’,‘S’,‘W’,\\\'N’四种,分别对应东南西北。执行某个命令时它会消耗1秒钟向对应的方向移动一格单位。 在0时刻机器人位于(0,0)。 如果遇到’E’命令,向右一个单位,即到达(1,0)。如果遇到’S’命令,向下一个单位,即到达

    2024年03月21日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包