High-dimensional network

Source: Internet
Author: User

High-dimensional network

"Problem description"

There is now a coordinate grid of dimensions, where the range of dimension coordinates is [0,].

Create a graph in this range: we put the whole point within the range (each dimension coordinates are

Integer points) as vertices on the graph. SetPoint (0,0,?, 0), (1, 2,?,).

For a range of points (1, 2,?,), it will be to these points (if the target point is in range):

(1 + 1, 2,?,), (1, 2 + 1,?,),? , (1, 2,?, + 1) connected to the edge.

Now there are a number of paths from point to place, and the number of paths can be calculated very simply. Unfortunately, there is a point in the range that is destroyed (dot and dot will not be destroyed), where the first point of the sitting

Labeled (, 1,, 2,?,,). You need to figure out the number of path bars remaining from point to point.

Because the answer can be large, you only need to output the result of the 1,000,000,007 modulo.

Analysis:

This problem will only be 80 minutes:

When n=1 the result, there is a breakpoint of 0, no breakpoint is 1;

When n=2 or 3 o'clock, and a[i] range compared to the hour, DP;

When p=0, use the combined number formula.

Code implementation:

program Exam;

Const

pz=1000000007;

Var

I,j,k:longint;

D,p,x,y,z:longint;

Pan:boolean;

Ans,a1,a2,a3,sum:int64;

F2:ARRAY[-1..1000,-1..1000] of Int64;

B2:ARRAY[-1..1000,-1..1000] of Boolean;

T2:ARRAY[-1..1000,-1..1000] of Int64;

F3:ARRAY[-1..100,-1..100,-1..100] of Int64;

T3:ARRAY[-1..100,-1..100,-1..100] of Int64;

B3:ARRAY[-1..100,-1..100,-1..100] of Boolean;

A:ARRAY[1..10000] of Longint;

function f (a,b:int64): Int64;

Var

T,y:int64;

Begin

T:=1;

Y:=a;

While b<>0 do

Begin

if (b and 1) =1 then

T:=t*y MoD PZ;

Y:=y*y MoD PZ;

B:=b SHR 1;

End

Exit (t);

End

function comb (N,m:int64): Int64;

Var

I,j:longint;

A1,b1:int64;

Begin

A1:=1;

For I:=1 to M do

A1:= ((A1 mod PZ) * ((n-i+1) mod pz)) mod pz;

B1:=1;

For I:=1 to M do

b1:= ((b1 mod pz) * (i mod pz)) mod pz;

B1:=f (b1,pz-2);

A1:= ((A1 mod PZ) * (B1 mod pz)) mod pz;

Exit (A1);

End

function COM (t,sum:int64): Int64;

Var

I,j:longint;

A1,b1:int64;

Begin

A1:=1;

For i:=1 to Sum do

A1:= ((A1 mod pz) * (i mod pz)) mod pz;

B1:=1;

For J:=1 to T-do

For I:=1 to A[j] do

b1:= ((b1 mod pz) * (i mod pz)) mod pz;

B1:=f (b1,pz-2);

A1:= ((A1 mod PZ) * (B1 mod pz)) mod pz;

Exit (A1);

End

Begin

Assign (input, ' cube.in ');

Reset (input);

Assign (output, ' cube.out ');

Rewrite (output);

READLN (D,P);

Pan:=false;

If D=1 Then

Begin

If P=0 Then

Writeln (' 1 ');

If P>0 Then

Writeln (' 0 ');

End

If d=2 Then

Begin

For I:=1 to D do

Begin

Read (A[i]);

If a[i]>1000 Then

Pan:=true;

End

If Pan=false Then

Begin

For I:=1 to P do

Begin

READLN (x, y);

B2[x,y]:=true;

End

T2[0,0]:=1;

For i:=0 to A[1] do

For j:=0 to A[2] do

Begin

if (B2[i-1,j]=false) and (B2[i,j-1]=false) then

F2[I,J]:=F2[I-1,J] MoD pz+f2[i,j-1] mod pz+t2[i,j] mod pz;

if (B2[i-1,j]=false) and (b2[i,j-1]=true) then

F2[I,J]:=F2[I-1,J] MoD pz+0+t2[i,j] mod pz;

if (b2[i-1,j]=true) and (B2[i,j-1]=false) then

F2[I,J]:=0+F2[I,J-1] MoD pz+t2[i,j] mod pz;

if (b2[i-1,j]=true) and (b2[i,j-1]=true) then

F2[I,J]:=0+0+T2[I,J] MoD pz;

End

Writeln (f2[a[1],a[2]] mod pz);

End

if (pan=true) and (p=0) then

Begin

Ans:=comb (a[1]+a[2],a[1]);

Writeln (ANS);

End

End

If D=3 Then

Begin

For I:=1 to D do

Begin

Read (A[i]);

Sum:=sum+a[i];

If A[i]>100 Then

Pan:=true;

End

If Pan=false Then

Begin

Fillchar (B3,sizeof (B3), true);

For I:=1 to P do

Begin

READLN (x, y, z);

B3[x,y,z]:=false;

End

T3[0,0,0]:=1;

For i:=0 to A[1] do

For j:=0 to A[2] do

For k:=0 to A[3] do

Begin

if (b3[i-1,j,k]=true) and (B3[i,j-1,k]=true) and (b3[i,j,k-1]=true) then

F3[I,J,K]:=F3[I-1,J,K] MoD pz+f3[i,j-1,k] mod pz+f3[i,j,k-1] mod pz+t3[i,j,k] mod pz;

if (b3[i-1,j,k]=true) and (B3[i,j-1,k]=false) and (b3[i,j,k-1]=true) then

F3[I,J,K]:=F3[I-1,J,K] MoD pz+0+f3[i,j,k-1] mod pz+t3[i,j,k] mod pz;

if (b3[i-1,j,k]=true) and (B3[i,j-1,k]=true) and (B3[i,j,k-1]=false) then

F3[I,J,K]:=F3[I-1,J,K] MoD pz+f3[i,j-1,k] mod pz+0+t3[i,j,k] mod pz;

if (b3[i-1,j,k]=true) and (B3[i,j-1,k]=false) and (B3[i,j,k-1]=false) then

F3[I,J,K]:=F3[I-1,J,K] MoD pz+0+0+t3[i,j,k] mod pz;

if (B3[i-1,j,k]=false) and (B3[i,j-1,k]=true) and (b3[i,j,k-1]=true) then

F3[I,J,K]:=0+F3[I,J-1,K] MoD pz+f3[i,j,k-1] mod pz+t3[i,j,k] mod pz;

if (B3[i-1,j,k]=false) and (B3[i,j-1,k]=false) and (b3[i,j,k-1]=true) then

F3[I,J,K]:=0+0+F3[I,J,K-1] MoD pz+t3[i,j,k] mod pz;

if (B3[i-1,j,k]=false) and (B3[i,j-1,k]=true) and (B3[i,j,k-1]=false) then

F3[I,J,K]:=0+F3[I,J-1,K] MoD pz+0+t3[i,j,k] mod pz;

if (B3[i-1,j,k]=false) and (B3[i,j-1,k]=false) and (B3[i,j,k-1]=false) then

F3[I,J,K]:=0+0+0+T3[I,J,K] MoD pz;

End

Writeln (f3[a[1],a[2],a[3]] mod pz);

End

if (pan=true) and (p=0) then

Begin

Ans:=com (d,sum);

Writeln (ANS);

End

End

if (d>3) and (p=0) then

Begin

For I:=1 to D do

Begin

Read (A[i]);

Sum:=sum+a[i];

End

Ans:=com (d,sum);

Writeln (ANS);

End

if (d>3) and (p<>0) then

Writeln (' 0 ');

Close (input);

Close (output);

End.

High-dimensional network

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.