This Road dp problem can be described as more difficult, I think the 2h always feel that they do not bear the entire set of state of the state space I have no idea the state final defeat.
Correct answer is so that we certainly have a dimension i represents to the i This man dinner but before i eat seven people behind are likely to eat, so you have to add one dimension j said he and behind the 7 human condition, Because the cost of a meal and the person concerned so k denotes the last person to eat, which is not yet transferred a bit of a, k this dimension encompasses too many unnecessary attempt to modify the state of our state-dimensional representation i was away from the last meal of the people. Obviously [-8, 7].
Think carefully about this state have included all of the state space, it can begin to shift the state.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//#include<bits/stdc++.h> #include<iomanip> #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<queue> #include<deque> #include<cmath> #include<ctime> #include<cstdlib> #include<stack> #include<algorithm> #include<vector> #include<cctype> #include<utility> #include<set> #include<bitset> #include<map> #define INF 1000000000 #define ll long long #define min(x,y) ((x)>(y)?(y):(x)) #define max(x,y) ((x)>(y)?(x):(y)) #define RI register ll #define db double #define EPS 1e-8 using namespace std; char buf[1<<15],*fs,*ft; inline char getc() { return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++; } inline int read() { int x=0,f=1;char ch=getc(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();} return x*f; } // (F));SDOI DP for the Minimum queue time where consideration of (A | B) - (A & B) // clearly state f [i] [j] [ k] indicates to the person i and themselves and the back 7 whether eat state j people who eat a distance i is the minimum cost when K. const int MAXN = 1010 ; int n-, T, Maxx; int a [MAXN], B [MAXN]; int F [MAXN] [ . 1 << . 8 ] [ 20 is ]; int main () { // The freopen ( "1.In", "R & lt", stdin); T = Read (); the while (T-- ) { n- = Read (); Memset (F, 10 , the sizeof Maxx = F [ 0 ] [0][0]; for(int i=1;i<=n;++i)a[i]=read(),b[i]=read(); f[1][0][7]=0;//k的值域 [-8,7] 整体平移8 for(int i=1;i<=n;++i) { for(int j=0;j<(1<<8);++j) { for(int k=0; K <= 15 ; ++ k) { IF (F [I] [J] [K] == Maxx) Continue ; IF (& J . 1 ) F [I + . 1 ] [J >> . 1 ] [- K- . 1 ] = min (F [I + . 1 ] [J >> . 1 ] [- K- . 1 ], F [I] [J] [K]); the else { int limit = Maxx; for ( int L = 0 ; L <= . 7 ; + L +) // enumerate the following who eat { IF (J & ( . 1 << L))continue; if(i+l>limit)break; limit=min(limit,i+l+b[i+l]); f[i][j|(1<<l)][l+8]=min(f[i][j|(1<<l)][l+8],f[i][j][k]+((i+k-8)?(a[i+k-8]^a[i+l]):0)); //cout<<f[i][j|(1<<l)][l+8]<<endl; } } } } } int ans=maxx; for(int i=0;i<=8;++i)ans=min(ans,f[n+1][0][i]); printf("%d\n",ans); } return 0; }
Sahua ~