@KirinBill
2018-03-07T23:15:10.000000Z
字数 6023
阅读 1126
套题
puts("gg");
目录
#include <cstdio>
const int MAXN=2005,P=998244353;
int n,psb;
int p[MAXN][MAXN];
inline int pow(int x,int y){
int ret=1;
for(;y;x=(long long)x*x%P,y>>=1){
if(y&1) ret=(long long)ret*x%P;
}
return ret;
}
inline int inv(int x){return pow(x,P-2);}
inline void cal_p(){
p[0][0]=1;
for(int i=1;i<=n;++i){
for(int j=0;j<i;++j){
p[i][j]=(p[i][j]+(long long)p[i-1][j]*pow((1-psb+P)%P,j)%P)%P;
p[i][j+1]=(p[i][j+1]+(long long)p[i-1][j]*pow(psb,i-(j+1))%P)%P;
}
}
}
inline int cal_f(){
static int f[MAXN];
f[1]=1;
for(int i=2,tmp;i<=n;++i){
tmp=0;
for(int j=1;j<i;++j)
tmp=(tmp+(long long)f[j]*p[i][j]%P)%P;
f[i]=(1-tmp+P)%P;
}
return f[n];
}
int main(){
freopen("diyiti.in","r",stdin);
freopen("diyiti.out","w",stdout);
int a,b;
scanf("%d%d%d",&n,&a,&b);
psb=(long long)a*inv(b)%P;
cal_p();
printf("%d",cal_f());
return 0;
}
#include <cstdio>
#include <cstring>
const int MAXN=5005,P=1e9+7;
int n;
int fac[MAXN],l[MAXN][MAXN],r[MAXN][MAXN];
int ans[MAXN];
char s[MAXN];
inline void cal_l(){
l[0][0]=1;
for(int i=1;i<=n;++i){
for(int j=1;j<=i;++j)
l[i][j]=(long long)l[i-1][j]*j%P;
if(s[i]=='<'){
for(int j=1;j<=i;++j)
l[i][j]=(l[i][j]+(long long)l[i-1][j+1]*(j+1)%P*j%P)%P;
}
else{
for(int j=1;j<=i;++j)
l[i][j]=(l[i][j]+l[i-1][j-1])%P;
}
}
}
inline void cal_r(){
r[n+1][0]=1;
for(int i=n,lim;i;--i){
lim=n-i+1;
for(int j=1;j<=lim;++j)
r[i][j]=(long long)r[i+1][j]*j%P;
if(s[i]=='>'){
for(int j=1;j<=lim;++j)
r[i][j]=(r[i][j]+(long long)r[i+1][j+1]*(j+1)%P*j%P)%P;
}
else{
for(int j=1;j<=lim;++j)
r[i][j]=(r[i][j]+r[i+1][j-1])%P;
}
}
}
inline void pre_fac(){
fac[0]=1;
for(int i=1;i<=n;++i)
fac[i]=(long long)fac[i-1]*i%P;
}
inline void DP(){
for(int i=1;i<=n;++i){
for(int j=0;j<=n;++j){
ans[i]=(ans[i]+(long long)l[i-1][j+1]*fac[j+1]%P*r[i+1][j]%P*fac[j]%P)%P;
ans[i]=(ans[i]+(long long)l[i-1][j]*fac[j]%P*r[i+1][j+1]%P*fac[j+1]%P)%P;
ans[i]=(ans[i]+((long long)l[i-1][j]*fac[j]%P*r[i+1][j]%P*fac[j]%P<<1)%P)%P;
}
}
}
int main(){
freopen("dierti.in","r",stdin);
freopen("dierti.out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
if(n==1){
putchar('1');
return 0;
}
cal_l();
cal_r();
pre_fac();
DP();
for(int i=1;i<=n;++i)
printf("%d ",ans[i]);
return 0;
}
代码:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <climits>
#include <cstring>
using std::sort;
using std::vector;
using std::min;
const int MAXN=200005,MAXM=200005;
const long long INF=1LL<<60;
int n,m,ocnt;
long long dp[MAXM];
struct data{int u,v,s,t;}flight[MAXM];
struct option{
int now,tm,id;
bool type;
static bool cmp_tm(const option &a,const option &b){
return a.tm<b.tm || (a.tm==b.tm && a.type<b.type);
}
}opt[MAXM<<1];
inline long long sqr(long long x){return x*x;}
inline int slope(int i){return -(flight[i].t<<1);}
inline long long y_itsct(int i){return sqr(flight[i].t)+dp[i];}
inline long long cal(int i,int j){
return (long long)slope(j)*flight[i].s+y_itsct(j);
}
inline double itcpt(int i,int j){
return (double)(y_itsct(j)-y_itsct(i))/(slope(i)-slope(j));
}
inline long long DP(){
static int head[MAXN],tail[MAXN];
static vector<int> dq[MAXN];
sort(opt+1,opt+ocnt+1,option::cmp_tm);
memset(tail,-1,sizeof(tail));
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
++tail[1],dq[1].push_back(0);
long long ret=LLONG_MAX;
for(int i=1;i<=ocnt;++i){
if(opt[i].type==0){
if(head[opt[i].now]>tail[opt[i].now]) continue;
while(head[opt[i].now]<tail[opt[i].now] && cal(opt[i].id,dq[opt[i].now][head[opt[i].now]])>=cal(opt[i].id,dq[opt[i].now][head[opt[i].now]+1]))
++head[opt[i].now];
dp[opt[i].id]=cal(opt[i].id,dq[opt[i].now][head[opt[i].now]])+sqr(flight[opt[i].id].s);
}
else{
while(head[opt[i].now]<tail[opt[i].now] && itcpt(opt[i].id,dq[opt[i].now][tail[opt[i].now]-1])<=itcpt(dq[opt[i].now][tail[opt[i].now]],dq[opt[i].now][tail[opt[i].now]-1]))
--tail[opt[i].now],dq[opt[i].now].pop_back();
++tail[opt[i].now],dq[opt[i].now].push_back(opt[i].id);
if(opt[i].now==n) ret=min(ret,dp[opt[i].id]);
}
}
return ret;
}
int main(){
freopen("disanti.in","r",stdin);
freopen("disanti.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1,u,v,s,t;i<=m;++i){
scanf("%d%d%d%d",&u,&v,&s,&t);
flight[i]=(data){u,v,s,t};
opt[++ocnt]=(option){u,s,i,0};
opt[++ocnt]=(option){v,t,i,1};
}
printf("%lld",DP());
return 0;
}