当前位置: 首页 > news >正文

P5301 [GXOI/GZOI2019] 宝牌一大堆

P5301 [GXOI/GZOI2019] 宝牌一大堆

#include<bits/stdc++.h>
#define pb push_back
#define fir first
#define sec second
#define mp make_pair
#define int long long 
#define pii pair<int,int>
#define Blue_Archive return 0
using namespace std;
const int gsws[15] = {0,1,9,10,18,19,27,28,29,30,31,32,33,34};
template <typename T>
T Max(T x,T y) { return x > y ? x : y;}
template <typename T>
T Min(T x,T y) { return x < y ? x : y;}
template <typename T>
T Abs(T x) { return x < 0 ? -x : x;}
template <typename T>
T chkmax(T &x,T y) { return x = x > y ? x : y;}
template <typename T>
T &read(T &r)
{r = 0;bool w = 0;char ch = getchar();while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0,ch = getchar();while(ch >= '0' && ch <= '9') r =(r << 3) +(r << 1) +(ch ^ 48),ch = getchar();return r = w ? -r : r;
}int ans;
int cnt[35];
int g[40][10];
int f[40][10][5][6][6];bool baopai[35];namespace Calc
{int fac[15],pow2[50];inline void Cpre(){fac[0] = 1;for(int i = 1;i <= 10;++i){fac[i] = fac[i - 1] * i;}pow2[0] = 1;for(int i = 1;i <= 30;++i){pow2[i] = pow2[i - 1] * 2;}}inline int C(int x,int y) { return fac[x] / fac[y] / fac[x - y];}inline int cbp(int x,int y) { return baopai[x] ? pow2[y] : 1;}
}
using namespace Calc;
namespace How_to_get
{inline char getcha(){char ch;cin >> ch;return ch;}inline int getpai(){char ch = getcha();if(ch == '0'){return 0;}if(ch >= '1' && ch <= '9'){char ch2 = getcha();if(ch2 == 'm'){return ch - '0';}if(ch2 == 'p'){return 9 +(ch - '0');}if(ch2 == 's'){return 18 +(ch - '0');}}switch(ch){case 'E':return 28;case 'S':return 29;case 'W':return 30;case 'N':return 31;case 'Z':return 32;case 'B':return 33;case 'F':return 34;}return 0;}
}
using namespace How_to_get;inline void read1()
{int x = getpai();while(x){cnt[x]--;x = getpai();}
}inline void read2()
{int x = getpai();while(x){baopai[x] = 1;x = getpai();}
}inline int Gsws()
{Cpre();int sumq = 0,mul = 1,bps = 0;for(int i = 1;i <= 13;++i){if(cnt[gsws[i]] == 0){return 0;}}for(int i = 1;i <= 13;++i){mul *= cnt[gsws[i]];bps += baopai[gsws[i]];}for(int i = 1;i <= 13;++i){if(cnt[gsws[i]] <= 1){continue;}sumq = Max(sumq,mul / cnt[gsws[i]] * C(cnt[gsws[i]],2) * pow2[bps + baopai[gsws[i]]]);}return sumq * 13;
}inline void dp1(int l,int r)
{for(int i = l;i <= r;++i){for(int j = 0;j <= 4;++j){for(int k = 0;k <= 1;++k){for(int c1 = 0;c1 <= 4;++c1){for(int c2 = 0;c2 <= 4;++c2){if(!f[i][j][k][c1][c2]){continue;}if(j == 4 && k){chkmax(ans,f[i][j][k][c1][c2]);}if(j + 1 <= 4 && cnt[i + 1] >= 3){chkmax(f[i + 1][j + 1][k][3][c1],f[i][j][k][c1][c2] * C(cnt[i + 1],3) * cbp(i + 1,3));}for(int p = 1;p <= 2;++p){if(j + p <= 4 && i >= 2 && cnt[i + 1] >= p && c1 <= cnt[i] - p && c2 <= cnt[i - 1] - p){chkmax(f[i + 1][j + p][k][p][c1 + p],f[i][j][k][c1][c2] / C(cnt[i],c1) / C(cnt[i - 1],c2) * C(cnt[i + 1],p) * C(cnt[i],c1 + p) * C(cnt[i - 1],c2 + p) * cbp(i + 1,p) * cbp(i,p) * cbp(i - 1,p));}}if(j + 2 <= 4 && i >= 2 && cnt[i + 1] >= 4 && c1 < cnt[i] && c2 < cnt[i - 1]){chkmax(f[i + 1][j + 2][k][4][c1 + 1],f[i][j][k][c1][c2] / C(cnt[i],c1) / C(cnt[i - 1],c2) * C(cnt[i + 1],4) * C(cnt[i],c1 + 1) * C(cnt[i - 1],c2 + 1) * cbp(i + 1,4) * cbp(i,1) * cbp(i - 1,1));}if(cnt[i + 1] >= 2 && !k){chkmax(f[i + 1][j][1][2][c1],f[i][j][k][c1][c2] * C(cnt[i + 1],2) * cbp(i + 1,2));}if(j + 1 <= 4 && i >= 2 && cnt[i + 1] >= 3 && !k && c1 < cnt[i] && c2 < cnt[i - 1]){chkmax(f[i + 1][j + 1][1][3][c1 + 1],f[i][j][k][c1][c2] / C(cnt[i],c1) / C(cnt[i - 1],c2) * C(cnt[i + 1],3) * C(cnt[i],c1 + 1) * C(cnt[i - 1],c2 + 1) * cbp(i + 1,3) * cbp(i,1) * cbp(i - 1,1));}chkmax(f[i + 1][j][k][0][c1],f[i][j][k][c1][c2]);if(j + 2 <= 4 && i >= 2 && cnt[i + 1] >= 4 && !k && c1 < cnt[i] - 1 && c2 < cnt[i - 1] - 1){chkmax(f[i + 1][j + 2][1][4][c1 + 2],f[i][j][k][c1][c2] / C(cnt[i],c1) / C(cnt[i - 1],c2) * C(cnt[i + 1],4) * C(cnt[i],c1 + 2) * C(cnt[i - 1],c2 + 2) * cbp(i + 1,4) * cbp(i,2) * cbp(i - 1,2));}chkmax(f[i + 1][j][k][0][c1],f[i][j][k][c1][c2]);}}}}}
}inline void dp2(int l,int r)
{for(int i = l;i <= r;++i){for(int j = 0;j <= 4;++j){for(int k = 0;k <= 1;++k){for(int c1 = 0;c1 <= 4;++c1){for(int c2 = 0;c2 <= 4;++c2){if(!f[i][j][k][c1][c2]){continue;}if(j == 4 && k){chkmax(ans,f[i][j][k][c1][c2]);}if(j + 1 <= 4 && cnt[i + 1] >= 3){chkmax(f[i + 1][j + 1][k][3][c1],f[i][j][k][c1][c2] * C(cnt[i + 1],3) * cbp(i + 1,3));}if(cnt[i + 1] >= 2 && !k){chkmax(f[i + 1][j][1][2][c1],f[i][j][k][c1][c2] * C(cnt[i + 1],2) * cbp(i + 1,2));}chkmax(f[i + 1][j][k][0][c1],f[i][j][k][c1][c2]);}}}}}
}inline void solve()
{for(int i = 1;i <= 34;++i){cnt[i] = 4;baopai[i] = 0;}read1();read2();ans = 0;ans = Max(ans,Gsws());for(int i = 1;i <= 34;++i){for(int j = 0;j <= 4;++j){for(int k = 0;k <= 1;++k){for(int c1 = 0;c1 <= 4;++c1){for(int c2 = 0;c2 <= 4;++c2){f[i][j][k][c1][c2] = 0;}}}}}for(int i = 1;i <= 34;++i){for(int j = 0;j <= 7;++j){g[i][j] = 0;}}f[0][0][0][0][0] = 1;dp1(0,8);dp2(9,10);dp1(11,17);dp2(18,19);dp1(20,26);dp2(27,33);for(int c1 = 0;c1 <= 4;++c1){for(int c2 = 0;c2 <= 4;++c2){chkmax(ans,f[34][4][1][c1][c2]);}}g[0][0] = 7;for(int i = 0;i <= 33;++i){for(int j = 0;j <= 7;++j){if(!g[i][j]){continue;}if(j == 7){chkmax(ans,g[i][j]);}if(cnt[i + 1] >= 2 && j + 1 <= 7){chkmax(g[i + 1][j + 1],g[i][j] * C(cnt[i + 1],2) * cbp(i + 1,2));}chkmax(g[i + 1][j],g[i][j]);}}chkmax(ans,g[34][7]);cout << ans << '\n';
}signed main()
{// freopen("data.in","r",stdin);freopen("data.out","w",stdout);int T;read(T);while(T--) solve();Blue_Archive;
}
http://www.hskmm.com/?act=detail&tid=24472

相关文章:

  • 10.4 2025多校冲刺CSP模拟赛2 改题记录
  • 【比赛记录】2025CSP-S模拟赛58
  • 回忆有感
  • 框架高效的系统的演进如何塑造人工智能的深层语义分析能力
  • 『回忆录』高二上第一次月考——压力下的崛起,意料外的突破
  • AutoCAD 2025安装包下载 CAD免费下载 永久免费激活 附详细安装教程
  • 微分和积分的区别
  • 202509_QQ_secret
  • 4 对拍杂谈
  • Matlab R2024b下载及详细安装教程,附永久免费Matlab安装包
  • Luogu P1966
  • 题解:P14036 [PAIO 2025] Rooks
  • 2025/8/26
  • 27 考研初试时间大约是什么时候?
  • 数据结构 - 跳表 Skip List
  • 06. 定时器
  • NOIP之前的复健记录
  • Linux 命令行安装达梦数据库
  • Google开源Tunix:JAX生态的LLM微调方案来了
  • 实用指南:Matlab通过GUI实现点云的快速全局配准(FGR)
  • 『OI 回忆录』停课有感
  • 『回忆录』初三第三学月
  • 完整教程:MySQL 5.7 主主复制 + Keepalived 高可用配置实例
  • 题解:P14074 [GESP202509 五级] 有趣的数字和
  • 解码Huffman 编码与 Huffman 树
  • 『回忆录』初三来高中的半学期
  • 10.1 容器云部署准备(一) - 实践
  • 关于缓冲区以及输出方式
  • 漏洞赏金计划的困境:i915漏洞与ChromeOS、Intel赏金项目剖析
  • RippleNet: Propagating User Preferences on the Knowledge Graph for Recommender Systems