AT_sumitb2019_e Colorful Hats 2 题解
思路
一道数学智力题。
因为
统计现在总共有多少个红,蓝,绿的帽子,再判断有多少种颜色的帽子个数是和输入的数相等的,表示当前有多少种方案,最后累乘一下即可。
代码如下
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
#define per(i, r, l) for(int i = r; i >= l; -- i)
#define me0(a); memset(a, 0, sizeof a);
#define me3(a); memset(a, 0x3f, sizeof a);
#define PII pair<int, int>
#define il inline
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
il void read(int &n)
{
bool w = 0;
char c = getchar();
for(; c < 48 || c > 57; c = getchar())
w = c == 45;
for(n = 0; c >= 48 && c <= 57; c = getchar())
n = n * 10 + c - 48;
n = w ? -n : n;
}
il void write(int x, char a)
{
char c[40], s = 0;
if(x < 0) putchar(45), x = -x;
for(; x ;) c[s ++] = x % 10, x /= 10;
if(!s) putchar(48);
for(; s -- ;) putchar(c[s] + 48);
putchar(a);
}
const int MAXN = 100000;
int n;
int ans = 1;
int m[4];
main()
{
read(n);
rep(i, 1, n)
{
int x;
read(x);
int sum = 0, t = 0;
if(x == m[1]) ++ sum, t = 1;
if(x == m[2]) ++ sum, t = 2;
if(x == m[3]) ++ sum, t = 3;
ans *= sum;
ans %= MOD;
++ m[t];
}
cout << ans << '\n';
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步