ABC326
我又来提供 low 算法了。
从 D 开始。
我们把
那么就可以想到状压,然后把每一行和每一列的情况状态即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 6;
int row[maxn],col[maxn];
string ans[maxn];
int n;
string r,c;
int tot = 0;
void dfs(int x,int y)
{
if(x == n)
{
if(tot == 3 * n)
{
cout << "Yes\n";
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
cout << ans[i][j];
}
cout << '\n';
}
exit(0);//杀死程序
}
return ;
}
if(y == n)
{
dfs(x + 1,0);
return ;
}
dfs(x,y + 1);//填.
for(int i = 0;i < 3;i++)
{
if(row[x] == 0 && i + 'A' != r[x])
{
continue;
}
if(col[y] == 0 && i + 'A' != c[y])
{
continue;
}//这样可以保证题目所说的2,3条件
if(row[x] >> i & 1)
{
continue;
}
if(col[y] >> i & 1)
{
continue;
}//不可以填的情况
ans[x][y] = 'A' + i;
row[x] ^= 1 << i;
col[y] ^= 1 << i;
tot += 1;
dfs(x,y + 1);
ans[x][y] = '.';
row[x] ^= 1 << i;
col[y] ^= 1 << i;
tot -= 1;//回溯
}
}
int main()
{
cin >> n >> r >> c;
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
ans[i][j] = '.';
}
}
dfs(0,0);
cout << "No";
return 0;
}
不难。
其实就是每一个数取到的概率乘上每一个数的值即可。
设取到
为什么呢?
因为
所以就可以在
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int qpow(int a,int b)
{
int res = 1;
while(b)
{
if(b & 1)
{
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
int n;
signed main()
{
cin >> n;
int ans = 0,p = qpow(n,mod - 2);
for(int i = 1;i <= n;i++)
{
int a;
cin >> a;
ans = (p * a % mod + ans) % mod;
p = (p + p * qpow(n,mod - 2) % mod) % mod;
}
cout << ans << '\n';
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话