a的暴力解
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string.h>
#include<algorithm>
#define MAXX int(2e5+5)
#define mod 998244353
#define fff(i,j,k) for(int i=j;i<=k;i++)
#define fyy(i,j,k) for(int i=k;i>=j;i--)
#define ll long long
#define fre freopen("in.txt","r",stdin)
using namespace std;
int n;
int a[MAXX];
int b[MAXX];
int qp(int a, int b)
{
if (b == 1)return a;
if (b == 0)return 1;
if (b % 2 == 1)return qp(a * a, b / 2) * a;
return qp(a * a, b / 2);
}
int main()
{
//fre;
cin.tie(0); cout.tie(0); ios::sync_with_stdio;
cin >> n;
for (int i = 1; i <= n+2; i++)
a[i] = 1;
fff(i, 3, n+1)//构建三角形
{
cout << a[1] << " ";
fyy(j, 2, i - 1)
{
a[j] += a[j - 1];
cout << a[j] << " ";
}
cout << a[i] << " ";
cout << endl;
}
b[1] = 1;
cout << b[1] << " ";
fyy(j, 2, n+1)
{
b[j] = a[j - 1] + a[j];
cout << b[j] << " ";
}
b[n + 2] = 1;
cout << b[n + 2] << " ";
cout << endl;
int ans = 0;
fff(i, 1, n + 2)//小红正面的个数
fff(j, 1, i-1)
ans += a[j] * b[i];
cout << ans << " " << qp(2, 2 * n + 1);
double c = ans*1. / qp(2, 2 * n + 1);
cout << "ans=" << c;
}
#include<iostream>
#include<string.h>
#include<algorithm>
#define MAXX int(2e5+5)
#define mod 998244353
#define fff(i,j,k) for(int i=j;i<=k;i++)
#define fyy(i,j,k) for(int i=k;i>=j;i--)
#define ll long long
#define fre freopen("in.txt","r",stdin)
using namespace std;
int n;
int a[MAXX];
int b[MAXX];
int qp(int a, int b)
{
if (b == 1)return a;
if (b == 0)return 1;
if (b % 2 == 1)return qp(a * a, b / 2) * a;
return qp(a * a, b / 2);
}
int main()
{
//fre;
cin.tie(0); cout.tie(0); ios::sync_with_stdio;
cin >> n;
for (int i = 1; i <= n+2; i++)
a[i] = 1;
fff(i, 3, n+1)//构建三角形
{
cout << a[1] << " ";
fyy(j, 2, i - 1)
{
a[j] += a[j - 1];
cout << a[j] << " ";
}
cout << a[i] << " ";
cout << endl;
}
b[1] = 1;
cout << b[1] << " ";
fyy(j, 2, n+1)
{
b[j] = a[j - 1] + a[j];
cout << b[j] << " ";
}
b[n + 2] = 1;
cout << b[n + 2] << " ";
cout << endl;
int ans = 0;
fff(i, 1, n + 2)//小红正面的个数
fff(j, 1, i-1)
ans += a[j] * b[i];
cout << ans << " " << qp(2, 2 * n + 1);
double c = ans*1. / qp(2, 2 * n + 1);
cout << "ans=" << c;
}