现在的位置: 首页 > 综合 > 正文

【bzoj 1925】: [Sdoi2010]地精部落

2017年04月21日 ⁄ 综合 ⁄ 共 1299字 ⁄ 字号 评论关闭

http://www.lydsy.com/JudgeOnline/problem.php?id=1925

蒟蒻又是不会啊

题解1

http://hi.baidu.com/wjbzbmr/item/da020be63f6f41f92b09a410

题解2

http://www.cnblogs.com/zhber/p/4036040.html

#define _TEST _TEST
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
/************************************************
Code By willinglive    Blog:http://willinglive.cf
************************************************/
#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)
#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define LL long long
#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)
inline const int read()
{int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
/////////////////////////////////////////////////
int n,p;
int _f[2][4444];
#define f(a,b) _f[(a)&1][b]
/////////////////////////////////////////////////

/////////////////////////////////////////////////
void input()
{
    cin>>n>>p;
}
void solve()
{
	f(1,1)=1;
	rep(i,2,n)
	{
		rep(j,1,i)
		{
			f(i,j)=f(i,j-1)+f(i-1,i-j);
			if(f(i,j)>=p) f(i,j)-=p;
		}
	}
	cout<<(2*f(n,n))%p<<endl;
}
/////////////////////////////////////////////////
int main()
{
    #ifndef _TEST
    freopen("std.in","r",stdin); freopen("std.out","w",stdout);
    #endif
    input(),solve();
    return 0;
}

抱歉!评论已关闭.