ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CF1513-B. AND Sequences

2021-10-01 19:03:55  阅读:159  来源: 互联网

标签:CF1513 &... int res Sequences 序列 include define


题意

题目定义了“好的序列”的定义:

对于一个长度为\(n\)的数字序列\(p\),如果对于每个\(i(2\le i \le n-1)\),如果都有\(p[1]\&p[2]\&...\&p[i]=p[i+1]\&p[i+2]\&...\&p[n]\),那么就称这个序列为好序列。

给出\(n(n \ge 2)\)个数字,问你能构造出多少个不同的“好的序列”。

思路

对于\(p[1]=p[2]\&p[3]\&...\&p[n]\),两边同时\(\&p[1]\)可以得到\(p[1]\&p[1]=p[1]\&p[2]\&p[3]\&...\&p[n]\).

同样的可以得到\(p[1]\& p[2]\&p[3]\&...\&p[n - 1] = p[n]\).

这里设\(t=p[1]\&p[2]\&p[3]\&...\&p[n]\)。

对于两边确定了之后的序列,无论如何都会对\(t\)取\(\&\),而\(t\)中又包含了序列中所有的数字,所以值是不会变的。

因此对于题目给出的序列,我们求出\(t\),然后看序列中有多少个与\(t\)相等的序列,取一个排列组合就可以了。

\(A_{n_t}^2*(n-n_t)!\).

代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <stack>
#include <cstdlib>
#include <map>
#include <queue>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <set>
#include <ctime>
 
#define wa std::cerr << "----WARN----" << std::endl;
#define wl std::cerr << "********" << std::endl;
#define wr std::cerr << "~~~~~~~~" << std::endl;
#define PII pair<int, int>
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
typedef long long LL;
 
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const LL LINF = 1LL * 0x3f3f3f3f3f3f3f3f;
 
const int N = 200005;
 
int a[N];
 
void solve() {
    int n, k;
    std::cin >> n >> k;
    a[0] = k;
    for (int i = 1; i < n; i++) {
        std::cin >> a[i];
        k &= a[i];
    }
    LL res = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == k) res++;
    }
    LL ans = res * (res - 1) % MOD;
    for (int i = 1; i <= n - 2; i++) {
        ans = ans * i % MOD;
    }
    std::cout << ans << std::endl;
}
 
inline int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
 
signed main() {
    #ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	#endif
    int T = 1;
    T = read();
    while (T--) solve();
    return 0;
}

标签:CF1513,&...,int,res,Sequences,序列,include,define
来源: https://www.cnblogs.com/chantmee/p/15359869.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有