zoukankan      html  css  js  c++  java
  • CF-300D-Painting Square(dp or NTT)

    题意:http://codeforces.com/problemset/problem/300/D

    四分树 分k次的所有种类数,层数有限制

    思路:

    可以根据二叉树推广,不停往上加点的思想

    https://www.cnblogs.com/CJLHY/p/11099739.html

    首先讲dp:

    从方程看出 i-j 和 k-l 的地位其实是等价的,所以我们可以先搞 i+j 的所有情况,也就是 k+l的所有情况,记为temp【sum】

    而我们要的答案也就是 ans【i+j】== temp【i】【j】(就是叠两次)

    而NTT方法就是加快卷积https://www.luogu.com.cn/problemnew/solution/CF300D

     1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
     2 #include <cstdio>//sprintf islower isupper
     3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
     4 #include <iostream>//pair
     5 #include <fstream>//freopen("C:\Users\13606\Desktop\Input.txt","r",stdin);
     6 #include <bitset>
     7 //#include <map>
     8 //#include<unordered_map>
     9 #include <vector>
    10 #include <stack>
    11 #include <set>
    12 #include <string.h>//strstr substr strcat
    13 #include <string>
    14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
    15 #include <cmath>
    16 #include <deque>
    17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
    18 #include <vector>//emplace_back
    19 //#include <math.h>
    20 #include <cassert>
    21 #include <iomanip>
    22 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
    23 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
    24 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
    25 //******************
    26 clock_t __START,__END;
    27 double __TOTALTIME;
    28 void _MS(){__START=clock();}
    29 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
    30 //***********************
    31 #define rint register int
    32 #define fo(a,b,c) for(rint a=b;a<=c;++a)
    33 #define fr(a,b,c) for(rint a=b;a>=c;--a)
    34 #define mem(a,b) memset(a,b,sizeof(a))
    35 #define pr printf
    36 #define sc scanf
    37 #define ls rt<<1
    38 #define rs rt<<1|1
    39 typedef pair<int,int> PII;
    40 typedef vector<int> VI;
    41 typedef unsigned long long ull;
    42 typedef long long ll;
    43 typedef double db;
    44 const db E=2.718281828;
    45 const db PI=acos(-1.0);
    46 const ll INF=(1LL<<60);
    47 const int inf=(1<<30);
    48 const db ESP=1e-9;
    49 const int mod=7340033;
    50 const int N=(int)1e3+10;
    51 
    52 ll dp[50][N],temp[50][N];
    53 
    54 int main()
    55 {
    56     for(int i=0;i<=31;++i)dp[i][0]=temp[i][0]=1;
    57     for(int c=1;c<=31;++c)
    58     {
    59         for(int i=1;i<=1000;++i)
    60             for(int j=0;j<i;++j)
    61                 dp[c][i]=(dp[c][i]+temp[c-1][j]*temp[c-1][i-1-j]%mod)%mod;
    62         for(int i=1;i<=1000;++i)
    63             for(int j=0;j<=i;++j)
    64                 temp[c][i]=(temp[c][i]+dp[c][j]*dp[c][i-j]%mod)%mod;
    65     }
    66     int q;
    67     sc("%d",&q);
    68     while(q--)
    69     {
    70         int n,k;
    71         sc("%d%d",&n,&k);
    72         int cnt=0;
    73         while(n&1&&n>1)
    74         {
    75             cnt++;
    76             n/=2;
    77         }
    78         pr("%lld
    ",dp[cnt][k]);
    79     }
    80     return 0;
    81 }
    82 
    83 /**************************************************************************************/
  • 相关阅读:
    linux驱动程序之电源管理之标准linux休眠与唤醒机制分析(一)
    linux驱动程序之电源管理 之linux休眠与唤醒(2)
    linux驱动程序之电源管理之regulator机制流程 (1)
    ARM--存储管理器
    元朝皇帝列表 元朝历代皇帝简介
    linux下valgrind的使用概述
    linux之sort用法
    python的ftplib模块
    Python使用struct处理二进制(pack和unpack用法)
    Python使用struct处理二进制(pack和unpack用法)
  • 原文地址:https://www.cnblogs.com/--HPY-7m/p/12569103.html
Copyright © 2011-2022 走看看