20190813

 

Last night: tomorrow we exam, to test a tree dp;

This afternoon: exams, as long as the third question would like the minimum spanning tree + dp

4 minutes before the end of the examination: first question is to find the law balabala ......

 - Ouyang says

XOR and

Seeking the exclusive OR and 1-n

This is a question of full A

If you see the data range, it will not hit the table to find the law like

Uh……

dyeing

description

There is a tree of N nodes, with the nodes 1, 2 ..... N number. You give it stained so that the color of adjacent nodes different. There are M colors, with 1,2 M ..... number. Each node may number several transfection of the M colors, different staining protocol required by (9 + 10 ^ 7) remainder.

Input (color.in)

Line 1, two integers N, M, N the next row, the i-th row represents a node i may be the color of dye. The first integer ki, represents the number of colors can be dyed. Next ki integers, that can dyed color number. Finally, N-1 lines, each two integers Ai, Bi represent the edges (Ai, Bi).

Output (color.out)

A number of his party, that is the answer

 

Tree DP, modulo nausea;

#include<bits/stdc++.h>
#define ll long long
#define re return
#define inc(i,l,r) for(int i=l;i<=r;++i)

const int maxn=5005,mod=1000000007;
using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=. 1 ; 
    X = C ^ 48 ;
     the while ((C = getchar ())> = ' 0 ' && C <= ' . 9 ' ) X = X * 10 + (C ^ 48 );
     IF (F) X = - X; 
} 

LL n-, m, K, F [MAXN] [MAXN], size [MAXN]; 
Vector < int > G [MAXN]; 
// course, in order to simplify the space, with f [i] [j] = 1, is determined if there is such a color
// open int, 1LL * Vector
< int > :: Iterator IT; int HD [MAXN]; struct Node { int to, NT; } E [MAXN << . 1]; inline void add(int x,int y) { e[++k].to=y;e[k].nt=hd[x];hd[x]=k; e[++k].to=x;e[k].nt=hd[y];hd[y]=k; } inline void dfs(int x,int fa) { for(int i=hd[x];i;i=e[i].nt) { int v=e[i].to; if(v==fa)continue; dfs(v,x); for(it=G[x].begin();it!=G[x].end();++it) { int* = J IT; F [X] [J] = (F [X] [J] * (size [V] MOD-F + [V] [J]))% MOD;
       /// size [V] in molding process may take less than f [v] [j], with the remainder theorem according } }
for (IT = G [X] .begin ();! G = IT [X] .end (); ++ IT) { int J = * IT; size [X] = (size [X] + F [X] [J])% MOD; } } int main () { int X, Y; RD (n-); RD (m) ; inc is (I, . 1 , n-) { int J; RD (J); inc is (K, . 1 , J) { RD (X); G [I] .push_back (X); f[i][x]=1; } } inc(i,1,n-1) { rd(x),rd(y); add(x,y); } dfs(1,0); printf("%lld",size[1]); re 0; }

 

 New Three hegemony

Description Description

PP especially like to play real-time strategy game, but he felt those games where there are fly in the ointment. Disaster does not always come to the road, but only coming city, and roads can not be occupied, not to protect the authenticity of forage. So he developed the "New Three hegemony."

In this game, added to the impact of disasters on the road (that is, once the road W [i, j] affected by the disaster, then at a certain time, this road will not pass) and occupied the right road (for a road W [i, j], requires at least K [i, j] soldiers to hold).

PP can really master a short while, it took over the N-1 cities, plus the original there are N cities, but he missed the point ...... it is equally important to the defense, but now come and. Dawan Zhang only because so many cities need to build, PP estimate, takes about T days. He now spare no time to attack, and had good days in which to engage in the construction of T. So he would send soldiers occupied some roads to ensure that there are no road between the two cities (otherwise the enemy will divide and conquer, and is very dangerous). White soldiers not to work, each soldier must eat rations V day. Because of the disaster, the program may have changed (every time you need to change the K rations, the initial plan also requires K rations).

Because the game is PP series, so he knows when there are disasters. PP, but a very economical person, he hopes to spend at least T day rations in the defense of the road.

Input format InputFormat

The first row has five integers N, M, T, V, K. N represents the number of cities there, M is the number of roads, T represents the number of days of training needs, V represents the number of rations eaten every day for each soldier, K represents the number of modifying rations once spent. The following M rows, each row of three numbers A, B, C. A and B represents a road (the road is two-way) requires C soldiers to hold. M + 2 is the second row a number P, the P expressed disaster. P The following lines of the number 4, X, Y, T1, T2. X to Y represents a road in the past few days T1 to T2 will be affected by disasters.

Output format OutputFormat

T-day rations in the least expensive way of defense.

Sample input SampleInput

3 3 5 10 30
1 2 1
2 3 2
1 3 4
1
1 3 2 5

Sample output SampleOutput

180

Hint range data and comments

For all data: N <= 300, M <= 5000, T <= 50, P <= 8000

 

We have done a very similar problem is called 

[ZJOI2006] logistics and transport

But that question is for the most short-circuited,

This question is a minimum spanning tree

When the minimum spanning tree, to be noted that [IK] and the minimum spanning tree of this continuous

With a very subtle way, and to determine the prefix [IK] can be used if the path I;

#include<bits/stdc++.h>
#define re return
#define inc(i,l,r) for(int i=l;i<=r;++i)
 
const int maxn=305,maxm=4005,maxt=55;
using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

int n,m,T,V,K,P,hd[maxn];
int fa[maxn],f[maxt],flag[maxn][maxn],vis[maxn][maxn][maxt];


struct node{
    int fr,to,val;
    bool operator<(node b)const
    {
        re val<b.val;
    }
}e[maxm];

inline int find(int X) 
{ 
    Re X == FA [X] X:? FA [X] = Find (FA [X]); 
} 


inline int KRUS ( int ST, int ED) 
{ 
    inc is (I, . 1 , n-) FA [ I] = I; 
    
    int cost = 0 ;
     int CNT = 0 ; 
    inc is (I, . 1 , m) 
    { 
        int U = E [I] .fr, V = E [I] .to;
         IF (VIS [U] [ V] [ED]-VIS [U] [V] [ST]) Continue ; // if there is a difference, then this path is not available during this time
         IF (Find (U) =! Find (V)) 
        { 
            FA [FA [U]] =fa[v];
            cost+=e[i].val;
            ++cnt;
            if(cnt==n-1)re cost;
        }
    }
    re 0;    
}

int main()
{
    
    
    int x,y,z,t1,t2;
    rd(n),rd(m),rd(T),rd(V),rd(K);
    
    inc(i,1,T)f[i]=2147483647;
    
    inc(i,1,m)
    {
        rd(x),rd(y),rd(z);
        e[i]=(node){x,y,z};
    }
    
    sort(e+1,e+m+1);
    
    rd(P);
    inc(i,1,P)
    {
        rd(x),rd(y),rd(t1),rd(t2);
        inc(j,t1,t2)
        vis[x][y][j]=vis[y][x][j]=1;
    }
    
    
    inc(i,1,n)inc(j,i,n)inc(k,1,T)
    vis[i][j][k]+=vis[i][j][k-1];
    
    inc(i,1,T)
    {    
        inc(k,i,T)
        {
            int cost=krus(i-1,k);
            if(!cost)break;
            cost*=V;
            f[k]=min(f[k],f[i-1]+(k-i+1)*cost+K);
        }
    }
    
    printf("%d",f[T]);
    re 0;
} 

 

Guess you like

Origin www.cnblogs.com/lsyyy/p/11348520.html