Codeforces Round # FF (Div. 1)-A, B, C

Source: Internet
Author: User

Codeforces Round # FF (Div. 1)-A, B, C

A: DZY Loves Sequences

At first, I read the wrong question .. Sad.

The question is very simple, and the practice is very simple. DP.

Dp [I] [0]: The length obtained from the current position without changing the number.

Dp [I] [1]: to the current position, the length of a number is changed.

However, you need to forward and reverse the request.

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; # define maxn 111_int dp [maxn] [3]; int num [maxn]; int a [maxn]; int n; void dos (int maxx) {memset (dp, 0, sizeof (dp); memset (num,-1, sizeof (num); for (int I = n; I> = 1; I --) {if (a [I] = a [I + 1]) {if (dp [I] [1]
     
      
A [I-1]) {dp [I] [0] = dp [I-1] [0] + 1;} else {dp [I] [0] = 1 ;} dp [I] [1] = dp [I] [0]; num [I] = a [I]; if (a [I]> num [I-1]) {if (dp [I] [1]
      
        B: DZY Loves Modification
       

We can find that the size order of a vertical row remains unchanged, but every vertical row drops by p.

So we can enumerate x horizontal lines and y vertical lines.

# Include
        
         
# Include
         
          
# Include
          
           
# Include
           
            
# Include
            
             
Using namespace std; # define maxn 1100 # define LL _ int64int mp [maxn] [maxn]; int hh [maxn]; int ll [maxn]; LL ph [1100000]; LL pl [1100000]; priority_queue
             
               Que; int n, m, k, p; void chu () {ph [0] = pl [0] = 0; while (! Que. empty () que. pop (); for (int I = 1; I <= n; I ++) {que. push (hh [I]) ;}for (int I = 1; I <= k; I ++) {int x = que. top (); que. pop (); ph [I] = ph [I-1] + (LL) x; x = x-p * m; que. push (x) ;}while (! Que. empty () que. pop (); for (int I = 1; I <= m; I ++) {que. push (ll [I]) ;}for (int I = 1; I <= k; I ++) {int x = que. top (); que. pop (); pl [I] = pl [I-1] + (LL) x; x = x-p * n; que. push (x) ;}} int main () {while (~ Scanf ("% d", & n, & m, & k, & p) {memset (hh, 0, sizeof (hh )); memset (ll, 0, sizeof (ll); for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {scanf ("% d", & mp [I] [j]); hh [I] + = mp [I] [j]; ll [j] + = mp [I] [j] ;}} chu (); LL ans = pl [k]; for (int I = 1; I <= k; I ++) {LL x = (LL) I * (LL) (k-I); x = (LL) x * (LL) p; ans = max (ans, pl [k-I] + ph [I]-x );} cout
              
               

There are two main properties:

1. The addition of two Fibonacci series is still a Fibonacci series.

2. According to the first two items of the Fibonacci series, the Fibonacci numbers at any position can be obtained in O (1) time, and the combination of the Fibonacci series of any length.

The rest is a simple question of range summation.

#include
                
                 #include
                 
                  #include
                  
                   #include
                   
                    #include#include
                    
                     #include
                     
                      #include
                      #pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define mem(a,b) (memset(a),b,sizeof(a))#define lmin 1#define rmax n#define lson l,(l+r)/2,rt<<1#define rson (l+r)/2+1,r,rt<<1|1#define root lmin,rmax,1#define now l,r,rt#define int_now int l,int r,int rt#define INF 99999999#define LL __int64#define mod 1000000009#define eps 1e-6#define zero(x) (fabs(x)
                       
                        r||rr
                        
                         =r) { f1[rt]+=fib[l-ll+1]; f2[rt]+=fib[l-ll+2]; sum[rt]+=suan(fib[l-ll+1],fib[l-ll+2],r-l+1); sum[rt]=(sum[rt]+mod)%mod; f1[rt]=f1[rt]%mod; f2[rt]=f2[rt]%mod; return; } push_down(now); updata(ll,rr,lson); updata(ll,rr,rson); push_up(now);}LL query(int ll,int rr,int_now){ if(ll>r||rr
                         
                          =r)return sum[rt]; push_down(now); return (query(ll,rr,rson)+query(ll,rr,lson))%mod;}int main(){ fib[1]=1;fib[2]=1; for(int i=3;i
                          
                           



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.