bzoj5158 [TJOI2014]Alice and Bob


Alice和Bob发明了一个新的游戏。给定一个序列{x0,x1,…,xn-1}。Alice得到一个序列{a0,a1,…,an-1},其中a;表示以x;结尾的最长上升子序列的长度;Bob得到一个序列{b0,b1,…,bn-1},其中bi表示以xi开头的最长下降子序列的长度。 Alice的得分是序列{a0,a1,…,an-1}的和,Bob的得分是{b0,b1,…,bn-1}的和。







输入样例#1: 复制

1 2 2 3
输出样例#1: 复制

输入样例#2: 复制

1 1 2 3
输出样例#2: 复制


对于 30% 的数据,N ≤ 1000

对于 100% 的数据,N ≤ 10^5

真是sb 树状数组求dp都yy了很久 直接到这来做思维难度直线下降

考虑贪心的去构造方案 模拟nlog(n) 求最长上升子序列的方法 这时候如果a相同 那么我必然让他们的c的权值递降更好 这样显然会对我b的答案产生更多帮助所以就每次记录一下最后一次出现的位置 然后直接从0开始dfs一下即可 因为加边..的顺序是反的.. 然后就构造出了c 然后求最长下降子序列 用树状数组倒序求即可

#define ll long long
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if(S==T){T=(S=now)+fread(now,1,1<<16,stdin);if(T==S) return EOF;}
    return *S++;
inline int read(){
    int x=0,f=1;char ch=gc();
    while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
    return x*f;
const int N=1e5+10;
struct node{
    int y,next;
int num,h[N],last[N],c[N],s[N],n;ll ans;
inline void insert1(int x,int y){
inline void dfs(int x){
    for (int i=h[x];i;i=data[i].next) dfs(data[i].y);
inline void add(int x,int v){while(x<=n+1) s[x]=max(s[x],v),x+=x&-x;}
inline int query(int x){static int tmp;
    tmp=0;while(x) tmp=max(tmp,s[x]),x-=x&-x;return tmp;
int main(){
    for (int i=1;i<=n;++i){
        static int x;x=read();
    //for (int i=1;i<=n;++i) printf("%d ",c[i]);
    for (int i=n;i;--i){static int tmp;
    return 0;

Alice and Bob


"Alice and Bob take turns choosing one of the numbers, and replace it with one of its positive factor but not itself. The one who makes the product of all numbers become 1 wins."nnAlice and Bob meet again this week, they played the game as description above last week. But Bob is so stupid that he had to spend lots of time on picking up "one of the number's factor but not itself". So Alice puts up a new game which needn't deal with the number. Here comes the problem.nnAlice and Bob take turns choosing one of the toys to move on the map, at the beginning of the game, they have M toys to choose. At each turn, they must choose one toy on the map, and make it move, the toy which the player chooses to move would not stay in the same place as last turn. There are N places on the map, naming 1, 2, 3, ..., N-1, N, the initial places of M toys are among these 1, 2, 3, ..., N-1 places, except the place N. Each of the M toys has a distinct initial place. If two different toys arrive at the same place, the operation is also valid. Finally, the place N is the terminal place. After the toy is moved to the place N, it will be eliminated from the map. Of course the eliminated toys cannot be moved again. And notice that we assume Alice takes the first turn. The one who has no toys to move is the loser. Notice that even there are toys remaining on the map, it has the possibility that the player cannot move any toys forward. The player would lose in this situation. See the Case 2 in the Sample Input section.nnThe map is assured to be a directed acyclic graph and the map would not change in the game. As the one of the cleverest programmers in the world, you are asked to place the toys on the map (That means that you decide the value of M and the initial places of these M toys). So, you want to know that who will win in your arrangement, assuming both of them are clever enough to play this game. The number of the edges between places is no more than 100000.nnInputnnThere are multiple test cases. Each case begins with an integer N (1 ≤ N ≤ 10000) in one line. In the following N-1 lines, ith(1≤ i ≤N-1) line describe the places where place naming i can arrive. "Ci p1 p2 ... pCi" implies that the number of places i can arrive totally Ci places, p1, p2, ..., pCi respectively.nnThen input comes with an integer Q in one line. In the fowllowing Q(1≤ Q ≤ 100) lines, it containes an integer M(1≤ M ≤ N-1) and the name of M distinct places, which are the initial places of M toys at the beginning of the game.nThere would not be any empty lines between cases.nnOutputnnFor each case, the output begins with "Case c:" in one line, where c indicates the case number. Then print exactly one line for each query in each test case. If the winner would be Alice, print "Alice", otherwise print "Bob".nnSample Inputnn4n2 2 3n1 4n1 4n3n1 1n1 2n2 1 2n4n2 2 3n1 4n0n2n1 3n2 3 1n10n1 2n1 3n1 4n1 5n1 6n1 7n1 8n1 9n1 10n3n1 1n5 1 2 3 4 5n9 1 2 3 4 5 6 7 8 9nSample OutputnnCase 1:nBobnAlicenAlicenCase 2:nBobnAlicenCase 3:nAlicenAlicenAlice


  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他