博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TC SRM 615 AlternativePile
阅读量:7282 次
发布时间:2019-06-30

本文共 2989 字,大约阅读时间需要 9 分钟。

这个题的难度都在读题。

描述得非常绕。。

看懂了就会做了。

有一个长度为C的序列,通过将W变成R、G、B 使得序列满足以下的条件

将变化后的序列中的B去掉。

剩下的R、G的数量为2*M的倍数。

将其分成M个不想交的子序列,每个长度为2*D,使得每个子序列都是RGRGRG。。。。

求方案数。

两个要控制的地方

1、RG的数量

2、序列的任意前缀都不允许R的数量多余G超过M个

F[i][j][k]表示前i个,R与G的差为j-1(防止负数),R与G的和模M为K的方案数。

ANS = F[C][1][0];

 

// BEGIN CUT HERE// END CUT HERE#line 5 "AlternativePiles.cpp"#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef pair
pii;typedef vector
::iterator iter;const int MAXN = 5010;int F[MAXN][60][110];const int MOD = 1000000007;class AlternativePiles{ public: int count(string C, int M){ memset(F,0,sizeof(F)); F[0][1][0]=1; int L = C.size(); for (int i=1;i<=L;i++){ for (int j=1;j<=M+1;j++){ for (int k=0;k<2*M;k++){ if (C[i-1]=='R') F[i][j][k] = F[i-1][j-1][(k-1+2*M)%(2*M)]; if (C[i-1]=='G') F[i][j][k] = F[i-1][j+1][(k-1+2*M)%(2*M)]; if (C[i-1]=='B') F[i][j][k] = F[i-1][j][k]; if (C[i-1]=='W') F[i][j][k] = (F[i-1][j-1][(k-1+2*M)%(2*M)]+F[i-1][j][k])%MOD+F[i-1][j+1][(k-1+2*M)%(2*M)]; F[i][j][k]%=MOD; } } } return F[L][1][0]; }// BEGIN CUT HERE public: void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); } private: template
string print_array(const vector
&V) { ostringstream os; os << "{ "; for (typename vector
::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } void test_case_0() { string Arg0 = "WRGWWRGW"; int Arg1 = 2; int Arg2 = 3; verify_case(0, Arg2, count(Arg0, Arg1)); } void test_case_1() { string Arg0 = "RRGG"; int Arg1 = 1; int Arg2 = 0; verify_case(1, Arg2, count(Arg0, Arg1)); } void test_case_2() { string Arg0 = "BBBB"; int Arg1 = 5; int Arg2 = 1; verify_case(2, Arg2, count(Arg0, Arg1)); } void test_case_3() { string Arg0 = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"; int Arg1 = 50; int Arg2 = 265470435; verify_case(3, Arg2, count(Arg0, Arg1)); } void test_case_4() { string Arg0 = "WRWRGWWGWWWRWBWRWGWWRWBWWRGWBWGRGWWGWGRWGRWBRWBW"; int Arg1 = 7; int Arg2 = 7400348; verify_case(4, Arg2, count(Arg0, Arg1)); }// END CUT HERE};// BEGIN CUT HEREint main(){ AlternativePiles ___test; ___test.run_test(-1); return 0;}// END CUT HERE
View Code

 

转载于:https://www.cnblogs.com/qinhang3/p/3645959.html

你可能感兴趣的文章
Spark Pipeline
查看>>
Spark FPGrowth (Frequent Pattern Mining)
查看>>
二维vector基本使用
查看>>
节省微博互粉时间,使用全自动"一键关注"Chrome扩展程序
查看>>
iOS Getter 和Setter 注册xibcell
查看>>
安装Python的numpy库
查看>>
Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)...
查看>>
linux中切换用户方式su和su -的区别
查看>>
php面向对象
查看>>
CHIL-SQL-IN 操作符
查看>>
des 加密 iOS
查看>>
XML 对xml文件的crud的增加 create操作 增加元素 增加属性
查看>>
java TCP通信 socket 套接字 用图片上传轰炸服务器
查看>>
linux处理闰秒
查看>>
Python模块configparser(操作配置文件ini)
查看>>
平衡二叉树(笔记)
查看>>
分析Linux内核创建一个新进程的过程
查看>>
视图层 view
查看>>
免插件,简单实现上拉加载loading
查看>>
一个现象,
查看>>