bzoj5285: [Hnoi2018] Scavenger Hunt

portal

Problem solving ideas:

During the exam, I passed 70 in reverse search, and I can pass the bzoj, but I still read the correct solution, which is really surprising.

Looking at each bit, you can see that |0 and &1 are meaningless.
If the value of a bit is required, the last one appears after the last &0. For the opposite.
Consider writing all operators as a string of 01, let all | operators be 0, & operators be 1, and the ith bit represents the operator before the ith number.
Also consider the extraction of a certain digit of all Jiang's numbers into a 01 string, and observe how to make the final result 1.
It can be found that the rightmost bit is regarded as the highest bit, and the comparison from high to low is both 0 or 1 has no effect, the operator is 1 and the value is 0, it is illegal, otherwise it is legal.
Therefore, it can be found that the resulting operator string can be all 01 strings whose lexicographical order is smaller than the 01 string formed by the current bit.
Consider the 01 string ordering formed for each bit.
For each query, first observe whether it is legal, that is, whether there is a legal set of operators that satisfies the requirements for each bit of the query string.
That is, for the query string, the rank of all 0 bits in the 01 sequence formed by the corresponding bits in the original sequence is smaller than the rank of all 1 bits corresponding to the 01 string.
Then calculate the answer, it can be found that the number of legal operator strings corresponding to the 01 string is less than the smallest bit of 1, minus the number of legal operator strings of the 01 string corresponding to the bit less than the largest one.

Reprinted from https://blog.csdn.net/zlttttt/article/details/79983210

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int getint()
{
    int i=0,f=1;char c;
    for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar());
    if(c=='-')c=getchar(),f=-1;
    for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
    return i*f;
}
const int N=40005;
int n,l[N],r[N],a[N],b[N],c[N];
ll f[N/2][41][41];
ll dfs(int u,int x,int y)
{
    if(u>=n)return 1ll*(a[u]+x)*(b[u]+y)*c[u];
    if(f[u][x][y])return f[u][x][y];
    return f[u][x][y]=min(dfs(l[u],x+1,y)+dfs(r[u],x,y),dfs(l[u],x,y)+dfs(r[u],x,y+1));
}
int main()
{
    //freopen("road.in","r",stdin);
    //freopen("road.out","w",stdout);
    n=getint();
    for(int i=1,x;i<n;i++)
    {
        x=getint();
        l[i]=x>0?x:n-1-x;
        x=getint();
        r[i]=x>0?x:n-1-x;
    }
    for(int i=n;i<2*n;i++)a[i]=getint(),b[i]=getint(),c[i]=getint();
    cout<<dfs(1,0,0)<<'\n';
    return 0;
}
?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326130507&siteId=291194637