Curs 4

https://infoarena.ro/problema/apm2
https://infoarena.ro/problema/ct
https://infoarena.ro/problema/freakadebunic

https://codeforces.com/contest/1598/problem/E

2 2 8
1 1
1 1
1 1
2 2
1 1
1 2
2 1
1 1

///linia de sus
for(int x = 1; x<= n; ++x) 
  for(int y = 1; y <= n; ++y) {
  if(!marcat[x][y]) {
    for(int lung = 1;; ++lung) {
        int finalx = x + (lung+1)/2;
        marcat[finalx][finaly] = 1;
        int finaly = y + lung/2;
        if(finalx > n ||finaly >m) break;
        ans+=lung;
    }
    for(int lung = 1;; ++lung) {
        int finalx = x + lung/2;
        int finaly = y + (lung+1)/2;
        if(finalx > n ||finaly >m) break;
        ans+=lung;
    }
  }
}

for(int i = 1; i <= q; ++i) {
  cin >> x >> y;
  //in sus
    for(int lungsus = 1;; ++lung) {
        int finalx = x - (lung+1)/2;
       
        int finaly = y - lung/2;
        if(finalx <0  ||finaly < 0 || a[finalx][finaly] == 1) break;
           }
}
///jos
 lungjos
 
 if(a[x][y] == 0)
   ans += lungsus*lungjos;
 else
   ans - lungsus*lungjos;
}

https://www.codechef.com/LTIME100A/problems/MXMNSSUM?tab=statement
https://infoarena.ro/problema/spargere2
https://infoarena.ro/problema/economie
https://www.infoarena.ro/problema/aliens
https://codeforces.com/contest/269/problem/B

up[0][nod] = tata;
max[0][nod] = tata-nod
for(int pw = 1; pw <= log; ++pw)
for(int i=1; i <= n; ++i){
max[pw][nod] = max(max[pw-1][nod],max[pw-1][up[pw-1][nod];
up[pw][nod] = up[pw-1][up[pw-1][nod];

void dfs(int x, int height) {
  viz[x] = 1;
  h[x] = height;
  for(auto y : g[x]) {
    dfs(y,height+1);
  }
}
query(a,tata_mai_sus) {
  
  height = h[a] - h[tata_mai_sus];
  for(int pw = pwmax; pw>=1; --pw) { //cautarea binara a lui patrascu 
    if(pw <= height)  {
      ma = max(ma, max[pw][nod]);
      a = up[pw][npd];
      height = h[a] - h[tata_mai_sus];
    }
  }
}
1 2 3 4 5
0 1 2 2 4 1 6 0 8 8 10 10 12
int stramosi[pw][nod] = care este al 2^pw stramos al lui nod
cin >> n;
 for(int i = 1; i <= n; ++i)
   cin >> stramosi[0][i];
for(int pw=1; pw <= LG; ++pw)
   for(int i = 1; i <= n; ++i)
       stramosi[pw][i] = stramosi[pw-1][stramosi[pw-1][i]];
2
3 
4 
5
 for(int i = 1; i <= q; ++i) {
   cin >> nod >> stramos;
   9 = 8+1
   for(int pw = 0; pw <= log2; ++pw) {
     if((1<<pw)&stramos)
         nod = stramosi[pw][nod];     
   }
   cout << nod;
 }
 
 
 numar = 17
 for(int pw = 0 ; pw <= 31; ++pw) 
   if((1<<pw)&numar)
     cout << (1<<pw);
 

masca de biti = multime
123.....n

{1,4,7} = 
n = 10

0123456789
1001001000  = 2^ = {1,
{1,4,7} = 2^1 + 2^4 + 2^7 = 

dp[146]= dp[{1,4,7}]

int = 32
100000 = 17 biti
dp[{1,4,5} | 8] = min(dp[1] + trunghiul(4,5,8)
dp[mask] = aria minima consumata pentru a acoperi punctele din mask.
for(int mask = 0; mask < (1<<n)-1; ++mask)
  dp[mask] = inf;
for(int bit = 0; bit <= n; ++bit)
  dp[1<<bit] = 0;

for(int mask = 0; mask <= (1<<n)-1; ++mask) {
  if(mask are doar 3 biti)
      dp[mask] = aria bitilor;
  if(mask are doar 1 bit sau 2)
    dp[mask] = 0
    for(bit1 = 0 ; bit1 < n; bit1++)
          for(bit2 = 0 ; bit2 < n; bit2++)
              for(int bit3= 0; noul_bit < n; ++noul_bit) 
                if(1 << bit2 & x .... )
                
              {
                dp[mask] = min( dp[mask - 1<<bit1 - 1<<bit2 .... ] + aria(bit1,bit2,bit3)
              }
              
              cout << dp[(1<<n)-1;
}
DP[{1,3,5,7,8,9,}] = min(DP[{1,3,5,7,8,9,}],  DP[{1,7,8,}] + arie({5,9,3}))

STRAMOSI/Dinamica pe masti biti ( articol, pbinfo, infoarena)