• 【搜索】【剪枝】bzoj1306 [CQOI2009]match循环赛


    dfs+剪枝*4(通过得很勉强):

    1、只枚举一半的比赛,另一半直接得出。
    2、处理前缀和,若大于目标得分则剪枝
    3、前缀和加上若接下来全胜的得分 仍小于 目标得分,则剪枝。
    4、枚举到每个人的最后一场比赛时直接用 目标得分-前缀和 计算出最后一场的应得分。
    Code还是很简单的:
     1 #include<cstdio>
     2 using namespace std;
     3 const int f[]={3,1,0,0};
     4 int n,a[9],ans,Pre[9];
     5 void dfs(int x,int y)
     6 {
     7     if(Pre[x]>a[x])return;
     8     if(Pre[x]+(n-y+1)*3<a[x])return;
     9     if(x==n){ans++;return;}
    10     if(y==n)
    11       {
    12           int tmp=a[x]-Pre[x];
    13           if(tmp==2)return;
    14           Pre[y]+=f[tmp];
    15         dfs(x+1,x+2);
    16           Pre[y]-=f[tmp];
    17       }else{
    18     Pre[x]+=3;dfs(x,y+1);Pre[x]-=3;
    19     Pre[y]+=3;dfs(x,y+1);Pre[y]-=3;
    20     Pre[x]++;Pre[y]++;dfs(x,y+1);Pre[x]--;Pre[y]--;}
    21 }
    22 int main()
    23 {
    24     scanf("%d",&n);
    25     for(int i=1;i<=n;i++)
    26       scanf("%d",&a[i]);
    27     dfs(1,2);
    28     printf("%d
    ",ans);
    29     return 0;
    30 }
    ——The Solution By AutSky_JadeK From UESTC 转载请注明出处:http://www.cnblogs.com/autsky-jadek/
  • 相关阅读:
    audio元素
    获取页面中出现次数最多的三个标签以及出现次数
    vue ssr(server side rendering)
    python_2 python的编码声明
    python_1 python的编译过程
    bugs
    isPrototypeOf和 instanceof 的区别
    WebStorm 配置Git
    MongoDB 副本集搭建
    获取结算样式 getComputedStyle-currentStyle
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/3959466.html
Copyright © 2020-2023  润新知