首页 > 代码库 > bzoj 4008、4011、1499
bzoj 4008、4011、1499
全是扒题解,,,太弱了。。。
不乱BB了。
4008
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 0x3f3f3f3f 5 #define eps 1e-5 6 #define N 100005 7 using namespace std; 8 inline int ra() 9 { 10 int x=0,f=1; char ch=getchar(); 11 while (ch<‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} 12 while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} 13 return x*f; 14 } 15 int T; 16 int n,r,d[255]; 17 double p[255]; 18 double f[255][255],pw[255][255]; 19 int main(int argc, char const *argv[]) 20 { 21 T=ra(); 22 while (T--) 23 { 24 n=ra(); r=ra(); 25 memset(f,0,sizeof(f)); 26 for (int i=1; i<=n; i++) 27 { 28 scanf("%lf",&p[i]); 29 d[i]=ra(); 30 } 31 double ans=0; 32 for (int i=1; i<=n; i++) 33 { 34 pw[i][0]=1; 35 for (int j=1; j<=r; j++) pw[i][j]=pw[i][j-1]*(1-p[i]); 36 } 37 f[0][r]=1; 38 for (int i=0; i<n; i++) 39 for (int j=0; j<=r; j++) 40 { 41 f[i+1][j]+=f[i][j]*pw[i+1][j]; 42 if (j-1>=0) 43 { 44 f[i+1][j-1]+=f[i][j]*(1-pw[i+1][j]); 45 ans+=f[i][j]*(1-pw[i+1][j])*d[i+1]; 46 } 47 } 48 printf("%.10lf\n",ans); 49 } 50 return 0; 51 }
4011
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 0x3f3f3f3f 5 #define eps 1e-5 6 #define N 100005 7 using namespace std; 8 inline int ra() 9 { 10 int x=0,f=1; char ch=getchar(); 11 while (ch<‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} 12 while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} 13 return x*f; 14 } 15 const int mod=1e9+7; 16 LL ans=1; 17 int n,m,x,y,cnt; 18 int head[100005],d[100005],b[100005]; 19 LL f[100005],ine[200005]; 20 vector<int> st; 21 struct edge{ 22 int to,next; 23 }e[200005]; 24 void insert(int x, int y) 25 { 26 e[++cnt].next=head[x]; e[cnt].to=y; head[x]=cnt; 27 } 28 void dp() 29 { 30 f[y]=ans; 31 for (int i=1; i<=n; i++) if (!d[i]) st.push_back(i); 32 while (!st.empty()) 33 { 34 int now=st.back(); st.pop_back(); 35 f[now]=f[now]*ine[b[now]]%mod; 36 for (int i=head[now];i;i=e[i].next) 37 { 38 f[e[i].to]=(f[e[i].to]+f[now])%mod; 39 d[e[i].to]--; 40 if (!d[e[i].to]) st.push_back(e[i].to); 41 } 42 } 43 } 44 int main(int argc, char const *argv[]) 45 { 46 n=ra(); m=ra(); x=ra(); y=ra(); 47 ine[1]=1; 48 for (int i=2; i<=m+1; i++) ine[i]=(-ine[mod%i]*(mod/i)+mod)%mod;//?? 49 for (int i=1; i<=m; i++) 50 { 51 int xx=ra(),yy=ra(); 52 insert(xx,yy); 53 d[yy]++; 54 } 55 d[y]++; 56 for (int i=1; i<=n; i++) b[i]=d[i]; 57 for (int i=2; i<=n; i++) 58 ans=ans*d[i]%mod; 59 d[y]--; 60 if (y==1) {printf("%lld\n",ans); return 0;} 61 dp(); 62 ans=(ans-f[x]+mod)%mod; 63 printf("%lld\n",ans); 64 return 0; 65 }
1499
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 0x3f3f3f3f 5 #define eps 1e-5 6 #define N 100005 7 using namespace std; 8 inline int ra() 9 { 10 int x=0,f=1; char ch=getchar(); 11 while (ch<‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} 12 while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} 13 return x*f; 14 } 15 char a[205][205]; 16 int f[205][205]; 17 int xx[]={0,-1,1,0,0},yy[]={0,0,0,-1,1}; 18 int q[205],pos[205],head,tail; 19 int n,m,sx,sy,K,ans; 20 void push(int now, int val) 21 { 22 if (val==-inf) return; 23 while (val-now>q[tail] && head<=tail) tail--; 24 q[++tail]=val-now; 25 pos[tail]=now; 26 } 27 void dp(int p, int x, int y, int d, int T) 28 { 29 head=1,tail=0; int now=1; 30 while (x<=n && y<=m && x>=1 && y>=1) 31 { 32 if (a[x][y]==‘x‘) head=1,tail=0; 33 else push(now,f[x][y]); 34 while (now-pos[head]>T && head<=tail) head++; 35 if (head<=tail) f[x][y]=q[head]+now; 36 else f[x][y]=-inf; 37 ans=max(ans,f[x][y]); 38 x+=xx[d]; y+=yy[d]; 39 now++; 40 } 41 } 42 int main(int argc, char const *argv[]) 43 { 44 n=ra(); m=ra(); sx=ra(); sy=ra(); K=ra(); 45 for (int i=1; i<=n; i++) scanf("%s",a[i]+1); 46 for (int i=1; i<=n; i++) 47 for (int j=1; j<=m; j++) 48 f[i][j]=-inf; 49 f[sx][sy]=0; 50 for (int i=1; i<=K; i++) 51 { 52 int x=ra(),y=ra(),d=ra(); 53 if (d==1) for (int j=1; j<=m; j++) dp(i,n,j,d,y-x+1); 54 if (d==2) for (int j=1; j<=m; j++) dp(i,1,j,d,y-x+1); 55 if (d==3) for (int j=1; j<=n; j++) dp(i,j,m,d,y-x+1); 56 if (d==4) for (int j=1; j<=n; j++) dp(i,j,1,d,y-x+1); 57 } 58 printf("%d\n",ans); 59 return 0; 60 }
bzoj 4008、4011、1499
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。