2016 Multi-University Training Contest 5

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lv414333532/article/details/52107071

 

Divide the Sequence
Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 702    Accepted Submission(s): 368



题意:把所给数列分成m段,使m尽可能的大,要求是每段的前缀和为非负,
思路:从后往前,遇到>=0的和 计数加加;
Problem Description
Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not small than 0.
 

Input
The input consists of multiple test cases.
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2An.
1n1e6
10000A[i]10000
You can assume that there is at least one solution.
 

Output
For each test case, output an integer indicates the maximum number of sequence division.
 

Sample Input
 
  
6 1 2 3 4 5 6 4 1 2 -3 0 5 0 0 0 0 0
 

Sample Output
 
  
6 2 5
 

Author
ZSTU
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5790  5789  5788  5787  5786 
 

Statistic | Submit | Discuss | Note


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
#define LL long long
using namespace std;
const int N=1e6+10;
LL A[N];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            scanf("%lld",&A[i]);
        int ans=0;
        int i=n;
        LL tmp;
        while(i>0)
        {
            tmp=A[i--];
            while(tmp<0)
                tmp+=A[i--];
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Two

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1161    Accepted Submission(s): 536


Problem Description
Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and sequence B' are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not same. A' is a subsequence of A. B' is a subsequence of B. The subsequnce can be not continuous. For example, {1,1,2} has 7 subsequences {1},{1},{2},{1,1},{1,2},{1,2},{1,1,2}. The answer can be very large. Output the answer mod 1000000007.
 

Input
The input contains multiple test cases.

For each test case, the first line cantains two integers N,M(1N,M1000). The next line contains N integers. The next line followed M integers. All integers are between 1 and 1000.
 

Output
For each test case, output the answer mod 1000000007.
 

Sample Input
 
  
3 2 1 2 3 2 1 3 2 1 2 3 1 2
 

Sample Output
 
  
2 3
 

Author
ZSTU
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5790  5789  5788  5787  5786


 



#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#define LL long long
using namespace std;
const int N=1e3+10;
int A[N];
int B[N];
const LL MOD=1e9+7;
LL dp[N][N];
int main()
{
   int n,m;
   while(~scanf("%d%d",&n,&m))
   {
       for(int i=1;i<=n;i++)
        scanf("%d",&A[i]);
       for(int i=1;i<=m;i++)
        scanf("%d",&B[i]);
       memset(dp,0,sizeof(dp));
       for(int i=1;i<=n;i++)
       {
           for(int j=1;j<=m;j++)
           {
                if(A[i]==B[j])
                {
                    (dp[i][j]=(dp[i-1][j]+dp[i][j-1])+1)%=MOD;
                }
                else
                    (dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%MOD+MOD)%=MOD;
           }
       }
       //deque<>
       printf("%I64d\n",dp[n][m]);
   }
    return 0;
}

World is Exploding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 666    Accepted Submission(s): 315



容斥原理;

Problem Description
Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: abcd,1a<bn,1c<dn,Aa<Ab,Ac>Ad.
 

Input
The input consists of multiple test cases.
Each test case begin with an integer n in a single line.

The next line contains n integers A1,A2An.
1n50000
0Ai1e9
 

Output
For each test case,output a line contains an integer.
 

Sample Input
 
  
4 2 4 1 3 4 1 2 3 4
 

Sample Output
 
  
1 0
 

Author
ZSTU
 

Source
 


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#define LL long long
using namespace std;
const int N=1e5+10;
int A[N];
int B[N];
int rg[N];  ///rg(x)=∣{y∣x<y<=n,A​x​​<A​y​​}∣
int lg[N];///      {y∣1<=y<x,A​x​​<A​y​​}
int rs[N];
int ls[N];
int allg[N];
int sum[N];
int lowbit(int x)
{
    return x&(-x);
}
void update(int x,int num,int n)
{
    while(x<=n)
    {
        sum[x]+=num;
        x+=lowbit(x);
    }
}
int getsum(int x)
{
    int s=0;
    while(x>0)
    {
        s+=sum[x];
        x-=lowbit(x);
    }
    return s;
}
int main()
{
     int n;
     int k;
     LL sum1;
     while(~scanf("%d",&n))
     {
         for(int i=0;i<n;i++)
         {
             scanf("%d",&A[i]);
             B[i]=A[i];
         }
         sort(B,B+n);
        k=unique(B,B+n)-B;
         for(int i=0;i<n;i++)
            A[i]=lower_bound(B,B+k,A[i])-B+1;
            memset(ls,0,sizeof(ls));
            memset(lg,0,sizeof(ls));
            memset(rs,0,sizeof(ls));
            memset(rg,0,sizeof(ls));
            memset(sum,0,sizeof(sum));
        LL a=0,b=0;
         for(int i=0;i<n;i++)
         {
             ls[i+1]=getsum(A[i]-1);
             lg[i+1]=getsum(k)-getsum(A[i]);
             update(A[i],1,k);
             a+=ls[i+1];
         }
         sum1=0;memset(sum,0,sizeof(sum));
         for(int i=n-1;i>=0;i--)
         {
             rs[i+1]=getsum(A[i]-1);
             rg[i+1]=getsum(k)-getsum(A[i]);
             update(A[i],1,k);
             sum1+=rs[i];
             b+=rs[i+1];
         }
         LL ans=0;
         for(int i=1;i<=n;i++)
         {
              ans-=(ls[i]*rs[i]+rg[i]*rs[i]+rg[i]*lg[i]+ls[i]*lg[i]);
         }
         ans+=a*b;
         printf("%I64d\n",ans);
     }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/lv414333532/article/details/52107071