Gym - 101915A  Printing Books

题意:有一本书,从第X页开始,一共用了n位数字,求此书一共多少页。99就是两位数字,100就是三位数字。

思路:直接模拟即可,我用了一个high和一个low,因为我把数字按位数分成了几个部分,1-9,10-99,100-999等(实际上high会等于1000),这样就会low = 100,high = 999之类的了,如果遇到边界,比如刚开始时,low和high有所调整,比如low=x,high=999,以方便计算。

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); ll pre[];
ll num[];
ll get_n(ll x)
{
ll ans = ;
while(x){
x/=;
ans++;
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
ll n,x;
scanf("%lld%lld",&n,&x);
ll di =get_n(x);
ll low = x;
ll high=;
for(int i=;i<=di;i++){
high*=;
}
ll ans= ;
for(int i=di;i<=;i++){
ll t = (high - low)*i;
if(t<=n){n-=t;ans+=high-low;}
else{
if(n%i==){ans+=n/i;}
else{ans=-;}break;
}
low = high;
high*=;
}
printf("%lld\n",ans);
}
return ;
}

Gym - 101915B Ali and Wi-Fi

题意:Ali要去蹭WIFI,他可以同时蹭m个WIFI,每个WIFI有一个信号值,以及自己的坐标和信号半径,Ali可以获得的WIFI信号值就是蹭到的WIFI的代数和。Ali可以出现在任何位置,求Ali最多得到的信号值是多大。

思路:最后的答案一定在一个圆交的区域内取得,现在的问题就是如何找到这个区域,由于是浮点数,枚举是不可能的,但是我们起码可以知道,圆的交点一定在某个圆交的边界上,所以我们只需要枚举每个圆的交点,再判断交点的信号值的大小就可以得出答案了,但是考虑到内含这种情况,所以再把所有的圆心判断一遍。

求圆交的地方我抄了别人的板子,但是这板子有点长了,可能不是很适合在赛场上使用。还有不知道为什么,这板子用了using namespace std 会错,我也不知道为什么、

c语言--求两圆交点

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) std::cout<<#x<<" = "<<x<<std::endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const double eps = 1e-; struct circle
{
double x,y;
double r,w;
}c[];
struct point
{
double x,y;
}p[maxn];
int n,m;
int top = ; struct point_t {
double x, y;
}; struct circle_t {
struct point_t center;
double r;
}; int double_equals(double const a, double const b)
{
static const double ZERO = 1e-;
return fabs(a - b) < ZERO;
} double distance_sqr(struct point_t const* a, struct point_t const* b)
{
return (a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y);
} double distance(struct point_t const* a, struct point_t const* b)
{
return sqrt(distance_sqr(a, b));
} int insect(struct circle_t circles[], struct point_t points[])
{
double d, a, b, c, p, q, r;
double cos_value[], sin_value[];
if (double_equals(circles[].center.x, circles[].center.x)
&& double_equals(circles[].center.y, circles[].center.y)
&& double_equals(circles[].r, circles[].r)) {
return -;
} d = distance(&circles[].center, &circles[].center);
if (d > circles[].r + circles[].r
|| d < fabs(circles[].r - circles[].r)) {
return ;
} a = 2.0 * circles[].r * (circles[].center.x - circles[].center.x);
b = 2.0 * circles[].r * (circles[].center.y - circles[].center.y);
c = circles[].r * circles[].r - circles[].r * circles[].r
- distance_sqr(&circles[].center, &circles[].center);
p = a * a + b * b;
q = -2.0 * a * c;
if (double_equals(d, circles[].r + circles[].r)
|| double_equals(d, fabs(circles[].r - circles[].r))) {
cos_value[] = -q / p / 2.0;
sin_value[] = sqrt( - cos_value[] * cos_value[]); points[].x = circles[].r * cos_value[] + circles[].center.x;
points[].y = circles[].r * sin_value[] + circles[].center.y; if (!double_equals(distance_sqr(&points[], &circles[].center),
circles[].r * circles[].r)) {
points[].y = circles[].center.y - circles[].r * sin_value[];
}
return ;
} r = c * c - b * b;
cos_value[] = (sqrt(q * q - 4.0 * p * r) - q) / p / 2.0;
cos_value[] = (-sqrt(q * q - 4.0 * p * r) - q) / p / 2.0;
sin_value[] = sqrt( - cos_value[] * cos_value[]);
sin_value[] = sqrt( - cos_value[] * cos_value[]); points[].x = circles[].r * cos_value[] + circles[].center.x;
points[].x = circles[].r * cos_value[] + circles[].center.x;
points[].y = circles[].r * sin_value[] + circles[].center.y;
points[].y = circles[].r * sin_value[] + circles[].center.y; if (!double_equals(distance_sqr(&points[], &circles[].center),
circles[].r * circles[].r)) {
points[].y = circles[].center.y - circles[].r * sin_value[];
}
if (!double_equals(distance_sqr(&points[], &circles[].center),
circles[].r * circles[].r)) {
points[].y = circles[].center.y - circles[].r * sin_value[];
}
if (double_equals(points[].y, points[].y)
&& double_equals(points[].x, points[].x)) {
if (points[].y > ) {
points[].y = -points[].y;
} else {
points[].y = -points[].y;
}
}
return ;
} void solve(int i,int j)
{
struct circle_t circles[];
struct point_t points[];
circles[].center.x=c[i].x;circles[].center.y=c[i].y;circles[].r=c[i].r;
circles[].center.x=c[j].x;circles[].center.y=c[j].y;circles[].r=c[j].r; switch (insect(circles, points)) {
case -:
return;
case :
return;
case :{
++top;
p[top].x=points[].x;
p[top].y=points[].y;
return;}
case :{
++top;
p[top].x=points[].x;
p[top].y=points[].y;
++top;
p[top].x=points[].x;
p[top].y=points[].y;
}
}
} double cal(int i)
{
double ans = ;
std::priority_queue<double>num;
for(int j=;j<=n;j++){
double d1 = (c[j].x-p[i].x)*(c[j].x-p[i].x)+ (c[j].y-p[i].y)*(c[j].y-p[i].y);
double d2 = 1.0*c[j].r*c[j].r;
if(d2-d1>=-eps){num.push(c[j].w);}
}
for(int j=;j<=m;j++){
if(num.empty()){break;}
ans+=num.top();
num.pop();
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
top=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r,&c[i].w);
top++;
p[top].x = c[i].x;
p[top].y = c[i].y;
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
solve(i,j);
}
}
double ans =;
for(int i=;i<=top;i++){
ans = std::max(ans,cal(i));
}
printf("%.0f\n",ans);
}
return ;
}

Gym - 101915C Shahhoud Training Hussain

题意:每天可以得到P个题,但是只能做k个,问n天后还有多少个题没有做

思路:注意k>p的情况

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int main()
{
int T;
scanf("%d",&T);
ll k,p,n;
while(T--){
scanf("%lld%lld%lld",&k,&p,&n);
ll ans =max(0ll,k-p)*n;
printf("%lld\n",ans);
}
return ;
}

Gym - 101915D Largest Group

题意:给一个图,求最大团。

思路:图的最大团 = 补图的最大独立集

  二分图的最大独立集 = 顶点个数 - 最大匹配数

  原图的补图正好是二分图。直接上DFS会超时,虽然我的代码在普通图上面已经跑得很快了。

  要说这两条公式的证明,我也不太会。。。。

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); struct edge
{
int v,next,w;
}e[];
int head[],cur;
int T;
int n,m;
int mp[][];
int sx,ex; void add(int x,int y)
{
e[cur].v=y;
e[cur].w=;
e[cur].next=head[x];
head[x]=cur;
cur++; e[cur].v=x;
e[cur].w=;
e[cur].next=head[y];
head[y]=cur;
cur++;
} void build()
{
cur=;
memset(mp,,sizeof(mp));
memset(head,-,sizeof(head));
int x,y; for(int i=;i<=m;i++){
scanf("%d%d",&x,&y);
mp[x][y+n]=true;
}
for(int i=;i<=n;i++){
for(int j=n+;j<=*n;j++){
if(!mp[i][j]){add(i,j);}
}
}
for(int i=;i<=n;i++){
add(*n+,i);
add(i+n,*n+);
}
}
int book[],num[];
bool bfs()
{
memset(book,,sizeof(book));
for(int i=;i<=*n+;i++){
num[i]=head[i];
}
queue<int>q;
q.push(sx);
book[sx]=;
int t,x;
while(!q.empty()){
t =q.front();
q.pop();
int k=head[t];
while(k!=-){
x=e[k].v;
if(!book[x]&&e[k].w){
book[x]=book[t]+;
q.push(x);
}
k=e[k].next;
}
}
return book[ex]!=;
} int dfs(int u,int f)
{
if(u==ex){return f;}
int &k=num[u];
int sum=; while(k!=-){
if(book[e[k].v]==book[u]+&&e[k].w){
int d = dfs(e[k].v,min(f,e[k].w));
f-=d;e[k].w-=d;e[k^].w+=d;
sum+=d;
}
k=e[k].next;
}
return sum;
} int dinic()
{
int ans =;
while(bfs()){
int f;
while((f=dfs(sx,inf))>){
ans+=f;
}
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
build();
sx =*n+;ex=*n+;
printf("%d\n",*n-dinic());
}
return ;
}

Gym - 101915E Minesweeper

题意:玩扫雷啦!有一个r*c的格子,放置地雷有以下要求,1.每块空地周围的地雷不能超过m个 2.每个地雷傍边必有一个空地。求最多可以埋多少地雷。

思路:DFS,2的36次方也不是闹着玩的,但是可以加一些剪枝,这样便可以顺利AC

当时做的时候想到搜索但是被自己否定了,直到看到了这题解

传送门

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
bool mp[][];
int n,m,k;
int ans;
int to[][]={,,,,,-,-,,,,,-,-,,-,-};
bool check(int x,int y)
{
int cnt = ;
int tx,ty;
if(mp[x][y]==){
for(int i=;i<;i++){
tx = x+to[i][];
ty = y+to[i][];
if(mp[tx][ty]){
cnt++;
}
}
if(cnt>k){return false;}
else return true;
}
for(int i=;i<;i++){
tx=x+to[i][];
ty=y+to[i][];
if(tx>&&ty>&&tx<=n&&ty<=m&&!mp[tx][ty]){return true;}
}
return false;
} void dfs(int x,int y,int cnt,int last)
{
if(cnt+last<=ans){return;}
if(x>n){
if(check(n,m))ans=max(ans,cnt);
return;
}
for(int i=;i<=;i++){
mp[x][y]=i;
if(x==n){
if(check(x-,y-)&&check(x,y-)){
if(y==m&&check(x-,y)){
dfs(x+,,cnt+i,last-);
}
else if(y!=m){
dfs(x,y+,cnt+i,last-);
}
}
}
else if(y==m){
if(check(x-,y-)&&check(x-,y)){
dfs(x+,,cnt+i,last-);
}
}
else{
if(check(x-,y-)){
dfs(x,y+,cnt+i,last-);
}
}
}
} int main()
{
int T;
scanf("%d",&T); while(T--){
memset(mp,,sizeof(mp));
ans=;
scanf("%d%d%d",&n,&m,&k);
dfs(,,,n*m);
printf("%d\n",ans);
} return ;
}

Gym - 101915F A Missing Problem in TCPC2017

题意:给你n-1个1~n的不重复数字,问1~n中那个数字没有出现

思路:vis标记的灵活运用

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
bool vis[];
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n,x;
memset(vis,,sizeof(vis));
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&x);vis[x]=true;
} for(int i=;i<=n;i++){
if(!vis[i]){printf("%d\n",i);}
}
}
return ;
}

Gym - 101915G Robots

题意:有一颗树,数的每条边都有一个权值,规定1号节点位根节点。有一堆机器人,也有各自的权值。机器人从根节点出发,只走比自己权值小的那个权值最大的边。求所有机器人停下来的节点的标号之和。

思路:DFS,先走权值大的边,在回溯之前,判断那些机器人会在当前节点停下来,具体方法是将机器人存在一个优先队列里面,在判断时,将>=走下来路上的最大的边的机器人留下来。如果一个机器人的值小于这个值,那么它走不到这里,而且走的顺序是按边由大到小,机器人走到了这里,说明它不能走到除了此处子节点以外的其他地方。而在回溯时,这个节点的子节点已经被判断完了,机器人还留在这里,说明它走不下去。由此可知,我们的策略应该是正确的

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int n,m;
struct node
{
int v,w;
};
vector<node>u[maxn];
bool cmp(node a,node b)
{
return a.w>b.w;
}
bool vis[maxn];
ll ans;
priority_queue<int>q;
void dfs(int t,int f)
{
int siz =u[t].size();
vis[t]=true;
for(int i=;i<siz;i++){
if(!vis[u[t][i].v]){
dfs(u[t][i].v,max(f,u[t][i].w));
}
}
vis[t]=false;
while(!q.empty()&&f<q.top()){
q.pop();
ans+=t;
}
} int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
u[i].clear();
}
int x,y,z;
for(int i=;i<n;i++){
scanf("%d%d%d",&x,&y,&z);
u[x].push_back(node{y,z});
u[y].push_back(node{x,z});
}
for(int i=;i<=m;i++){
int x;
scanf("%d",&x);
q.push(x);
} for(int i=;i<=n;i++){
sort(u[i].begin(),u[i].end(),cmp);
}
ans = ;
dfs(,);
printf("%lld\n",ans);
}
return ;
}

Gym - 101915H Buying Products

题意:妻管严被老婆赶出去买东西,每个商店有3个商品,但是他只能买两个,一共要买m个商品,问最小花费。

思路:取每家商店的最便宜的两件商品,放在一起,买下最便宜的m个

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int num[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n,k;
scanf("%d%d",&n,&k);
int s[],t=;
for(int i=;i<=n;i++){
scanf("%d%d%d",&s[],&s[],&s[]);
sort(s,s+);
num[++t]=s[];num[++t]=s[];
}
sort(num+,num++t);
int ans = ;
for(int i=;i<=k;i++){
ans+=num[i];
}
printf("%d\n",ans);
} return ;
}

Gym - 101915I A Movie in Byteland

题意:有很多字符串,你可以将他们随便排列,但是前面的字符串正着看和反着看都要分别比后面的任何一个字符串的字典序要小,而且任何相邻的两个字符串要满足一个有字母m,一个没有。求给定的字符串中最大可以排出多大满足条件的序列。

思路:先正着排一次序,记下序号id。反着排一次序,按次序将id加入树状数组中。已经在树状数组中的数据,一定是第二次排序的序号小于当前字符串的,树状数组中,小于id的数据,就是第一次排序的序号小于当前字符串的。建立两个树状数组,便可以分别维护,以含有m的字符串结尾的字符串序列的最大值和以不含m的字符串结尾的字符串序列的最大值。

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int a[][maxn];
struct node
{
string s,t;
int m,id;
}ss[maxn];
int n; int lowbit(int x)
{
return x&(-x);
} int query(int m,int x){
int ans=;
while(x){
ans = max(ans,a[m][x]);
x-=lowbit(x);
}
return ans;
} void add(int m,int x,int num)
{
while(x<=n){
a[m][x]=max(a[m][x],num);
x+=lowbit(x);
}
} bool cmp(node a,node b)
{
return a.s<b.s;
} bool jud(node a,node b)
{
return a.t<b.t;
} int main()
{
int T;
cin>>T;
while(T--){
memset(a,,sizeof(a));
cin>>n;
for(int i=;i<=n;i++){
cin>>ss[i].s;
int siz = ss[i].s.size();
ss[i].t = ss[i].s;
ss[i].m = ;
for(int j=;j<siz;j++){
if(ss[i].s[j]=='m'){ss[i].m=;break;}
}
reverse(ss[i].t.begin(),ss[i].t.end());
}
sort(ss+,ss++n,cmp);
for(int i=;i<=n;i++){
ss[i].id=i;
}
sort(ss+,ss++n,jud);
int ans = ; for(int i=;i<=n;i++){
int tmp;
tmp = query(ss[i].m^,ss[i].id)+;
ans = max(tmp,ans);
add(ss[i].m,ss[i].id,tmp);
}
cout<<ans<<endl;
}
return ;
}

Gym - 101915J The Volcano Eruption

题意:有一个n*m的矩形框,你要从矩形顶走到矩形底,你想怎么走就怎么走,问最少通过多少区域。区域由圆形组成,两圆相交或相切视为同一区域。

思路:用并查集将圆合并,判断每一个并查集的左右边界,如果左右都超出了矩形框范围,那么答案++;

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define ls (t<<1)
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int f[maxn];
ll x[maxn],y[maxn],r[maxn];
int n;ll w,l;
ll L[maxn],R[maxn]; int getf(int x)
{
if(f[x]==x){return x;}
return f[x]=getf(f[x]);
} void Merge(int i,int j)
{
ll d1,d2;
ll x1,x2,y1,y2;
x1=x[i],y1=y[i],x2=x[j],y2=y[j];
d1=1ll*(x1-x2)*(x1-x2)+1ll*(y1-y2)*(y1-y2);
d2=(1ll*r[i]+1ll*r[j])*(1ll*r[i]+1ll*r[j]);
if(d1>d2){return;}
int t1 = getf(i);
int t2 = getf(j);
f[t2]=t1;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d%lld%lld",&n,&w,&l);
for(int i=;i<=n;i++){
scanf("%lld%lld%lld",&x[i],&y[i],&r[i]);
f[i]=i;
L[i]=Inf;R[i]=-;
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
Merge(i,j);
}
}
for(int i=;i<=n;i++){
int s=getf(i);
L[s]=min(L[s],x[i]-r[i]);
R[s]=max(R[s],x[i]+r[i]);
}
int ans =;
for(int i=;i<=n;i++){
if(L[i]<=&&R[i]>=w&&y[i]>=&&y[i]<=l){ans++;}
}
printf("%d\n",ans);
}
return ;
}

Gym - 101915K Poor Ramzi

题意:有一个01串,将其分成1若干份,每一份的值就是1的个数,以这个值组成一个新串,问新串的为回文串的划分方案数。

思路:DFS,由外向内搜索,逐步深入即可。

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
char s[maxn];
int dp[maxn][maxn];
ll dfs(int l,int r)
{
if(l>=r){return 1ll;}
if(dp[l][r]!=-){return dp[l][r];}
ll ans =;
int lsum = ,rsum = ;
for(int i=l;i<=r;i++){
lsum+=s[i]-'';
rsum =;
for(int j=r;j>i;j--){
rsum+=s[j]-'';
if(rsum ==lsum){
ans+=dfs(i+,j-);
ans%=mod;
}
}
}
ans++;
return dp[l][r]=(ans%=mod);
} int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%s",s);
memset(dp,-,sizeof(dp));
int len = strlen(s);
printf("%lld\n",dfs(,len-));
}
return ;
}

Gym-101915L Eyb0ss

题意:就是求题目的那个公式

思路:这个题目似曾相识,可是就是不知道怎么写,题解又搜不到,好气呀。

Gym 101915的更多相关文章

  1. J. The Volcano Eruption(圆相交+并查集)

    题目链接:https://codeforces.com/gym/101915/problem/J 思路:将所有相交的圆用并查集维护看做一个整体,然后枚举每个整体的左边界和右边界,判断能不能同时覆盖整个 ...

  2. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  7. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  8. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  9. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

随机推荐

  1. Hotspot Java虚拟机的类加载器

    从Java虚拟机角度来讲,有两种类加载器.1.启动类加载器.(Bootstrap ClassLoader,C++)2.所有其他类加载器.(Java,java.lang.ClassLoader) 系统提 ...

  2. Jenkins+PowerShell持续集成环境搭建(四)常用PowerShell命令

    0. 修改执行策略 Jenkins执行PowerShell脚本,需要修改其执行策略.以管理员身份运行PowerShell,执行以下脚本: Set-ExecutionPolicy Unrestricte ...

  3. Jetson TX1 install py-faster-rcnn

    Install py-faster-rcnn following the official version  https://github.com/rbgirshick/py-faster-rcnn ...

  4. JSON in SQL Server 2016

    JSON functions in SQL Server enable you to analyze and query JSON data, transform JSON to relational ...

  5. Windows Server2008、IIS7启用CA认证及证书制作完整过程

    1         添加活动目录证书服务 1.1          打开服务器管理器,右键点击角色,选择“添加角色”,在“添加角色向导”窗口左侧面板选择“服务器角色”,然后勾选“Active Dire ...

  6. python之旅六【第六篇】模块

    json和pickle 用于序列化的两个模块json,用于字符串 和 python数据类型间进行转换pickle,用于python特有的类型 和 python的数据类型间进行转换 json模块提供了四 ...

  7. 区间DP,数位DP

    dp(动态规划)顾名思义便是动态的一种规划,而这种规划往往会跟状态,状态转移方程,记忆化搜索扯上关系,当然DP也是各个OI考试的必考点和常考点,在毒瘤出题人的折磨下,出现了许许多多的动态规划,有线性, ...

  8. Django+Xadmin打造在线教育系统(五)

    课程相关功能实现 课程列表 创建课程相关的urls.py path("course/", include('course.urls', namespace="course ...

  9. FFT算法小结

    都应该知道多项式是什么对吧(否则学什么多项式乘法) 我们用\(A(x)\)表示一个\(n-1\)次多项式,即\(A(x)=\sum_{i=0}^{n-1} {a_i}*x^i\) 例如\(A(x)=x ...

  10. gulp 技巧

    install npm install --save-dev jshint gulp-jshint 压缩js npm install --save-dev gulp-minify-css xxCSS ...