zoukankan      html  css  js  c++  java
  • NOIp2018集训test-9-7(pm) (联考一day1)

    又被辉神吊打了。今天不仅被辉神李巨吊打,还给基本上给全班垫底了。

    看到T3就知道是十进制快速幂,全机房考试的当时应该就我会,结果我tm没找到递推。

    Orz lyc BM直接水过,Orz wys六个for循环出递推,Orz辉神手推n^2递推。

    不敢说话,我去背BM板子了。

    这样下去大概NOIp继续被辉神李巨吊打,可以退役回去学常规了。

    1 餐馆 (restaurant)

    完全背包裸题。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=5007; 
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int T,n,m,S,t[N],w[N];
    20 LL f[N],ans;
    21 
    22 template<typename T>void read(T &x)  {
    23     char ch=getchar(); x=0; T f=1;
    24     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    25     if(ch=='-') f=-1,ch=getchar();
    26     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    27 }
    28 
    29 #define ANS
    30 int main() {
    31 #ifdef ANS
    32     freopen("restaurant.in","r",stdin);
    33     freopen("restaurant.out","w",stdout);
    34 #endif
    35     read(T);
    36     while(T--) {
    37         memset(f,0,sizeof(f));
    38         read(n); read(m); read(S);
    39         For(i,1,n) {
    40             read(t[i]); read(w[i]);
    41         }
    42         For(i,1,m) { read(t[n+i]); read(w[n+i]); } 
    43         For(i,1,m) For(j,1,n) {
    44             int x; read(x);
    45             if(x>0) t[n+i]+=x*t[j];
    46         }
    47         For(i,1,n+m) For(j,t[i],S) 
    48             f[j]=max(f[j],f[j-t[i]]+w[i]);
    49         ans=0;
    50         For(j,0,S) ans=max(ans,f[j]);
    51         printf("%lld
    ",ans);
    52     }
    53     Formylove;
    54 }
    View Code

    2 烯烃 (olefin)

    树形dp裸题,最最基础的换根操作。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=1e5+7;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int id,T,n,m,tag[N],ans[N];
    20 
    21 template<typename T>void read(T &x)  {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 int ecnt,fir[N],nxt[N<<1],to[N<<1],fa[N];
    29 void add(int u,int v) {
    30     nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v;
    31 }
    32 
    33 int f[N];
    34 void dfs(int x) {
    35     f[x]=0;
    36     for(int i=fir[x];i;i=nxt[i]) {
    37         dfs(to[i]);
    38         f[x]=max(f[x],f[to[i]]+1);
    39     }
    40 }
    41 
    42 void get_max(int &a,int b) { if(b>a) a=b; }
    43 
    44 void dfs2(int x,int ff) {
    45     int se=0,fi=x==1?0:ff+1;
    46     for(int i=fir[x];i;i=nxt[i]) {
    47         se=max(se,f[to[i]]+1);
    48         if(se>fi) swap(fi,se); 
    49     }
    50     for(int i=fir[x];i;i=nxt[i]) if(tag[to[i]]) {
    51         if(fi==f[to[i]]+1) get_max(ans[tag[to[i]]],se+f[to[i]]+1);
    52         else get_max(ans[tag[to[i]]],fi+f[to[i]]+1);
    53     }
    54     for(int i=fir[x];i;i=nxt[i]) {
    55         if(f[to[i]]+1==fi) dfs2(to[i],se);
    56         else dfs2(to[i],fi);
    57     }
    58 }
    59 
    60 void init() {
    61     ecnt=0;
    62     memset(ans,0,sizeof(ans));
    63     memset(fir,0,sizeof(fir));
    64     memset(tag,0,sizeof(tag));
    65 }
    66 
    67 #define ANS
    68 int main() {
    69 #ifdef ANS
    70     freopen("olefin.in","r",stdin);
    71     freopen("olefin.out","w",stdout);
    72 #endif
    73     read(id);
    74     read(T);
    75     while(T--) {
    76         init();
    77         read(n); read(m);
    78         For(i,2,n) {
    79             read(fa[i]);
    80             add(fa[i],i);
    81         }
    82         For(i,1,m) {
    83             int x;
    84             read(x);
    85             tag[x]=i;
    86         }
    87         dfs(1);
    88         dfs2(1,0);
    89         For(i,1,m-1) printf("%d ",ans[i]);
    90         if(m) printf("%d
    ",ans[m]);
    91     }
    92     Formylove;
    93 }
    View Code

    3 三米诺 (tromino)

    十进制快速幂,我不会找递推,只能用背BM板子然后水过去。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=40007,p=998244353;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 char s[N];
    20 LL n,f[15]={0,1,3,10,23,62,170,441,1173,3127,8266};
    21 
    22 template<typename T>void read(T &x)  {
    23     char ch=getchar(); x=0; T f=1;
    24     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    25     if(ch=='-') f=-1,ch=getchar();
    26     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    27 }
    28 
    29 struct jz {
    30     LL a[6][6];
    31     friend jz operator *(const jz&A,const jz&B) {
    32         jz rs;
    33         For(i,0,5) For(j,0,5) {
    34             rs.a[i][j]=0;
    35             For(k,0,5) 
    36                 (rs.a[i][j]+=A.a[i][k]*B.a[k][j]%p)%=p;
    37         }
    38         return rs;
    39     }
    40 }bs,rs;
    41 
    42 void ksm() {
    43     int len=strlen(s);
    44     int ok=0;
    45     Rep(i,len-1,0) {
    46         int c;
    47         c=s[i]-'0';
    48         if(!ok) {
    49             c--; 
    50             if(c<0) c+=10;
    51             else ok=1;
    52         }
    53         For(i,1,c) rs=rs*bs;
    54         jz pr=bs;
    55         For(i,1,9) bs=bs*pr;
    56     }  
    57 }
    58 
    59 #define ANS
    60 int main() {
    61 #ifdef ANS
    62     freopen("tromino.in","r",stdin);
    63     freopen("tromino.out","w",stdout);
    64 #endif
    65     scanf("%s",s);
    66     For(i,0,5) For(j,0,5) rs.a[i][j]=bs.a[i][j]=0;
    67     For(i,0,5) {
    68         rs.a[i][i]=1;
    69         if(i<5) bs.a[i+1][i]=1;
    70     }
    71     bs.a[5][5]=1;
    72     bs.a[4][5]=2;
    73     bs.a[3][5]=6;
    74     bs.a[2][5]=1;
    75     bs.a[0][5]=p-1;
    76     ksm();
    77     LL ans=0;
    78     For(i,0,5) 
    79         (ans+=rs.a[i][0]*f[i+1]%p)%=p;
    80     printf("%lld
    ",ans);
    81     Formylove;
    82 }
    View Code
  • 相关阅读:
    给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。
    11
    实战 迁移学习 VGG19、ResNet50、InceptionV3 实践 猫狗大战 问题
    tx2系统备份与恢复
    如何在Ubuntu 18.04上安装和卸载TeamViewer
    bzoj 3732 Network (kruskal重构树)
    bzoj2152 聪聪可可 (树形dp)
    牛客 216D 消消乐 (二分图最小点覆盖)
    牛客 197E 01串
    Wannafly挑战赛23
  • 原文地址:https://www.cnblogs.com/Achenchen/p/9607815.html
Copyright © 2011-2022 走看看