zoukankan      html  css  js  c++  java
  • 母函数模板

    HDU1398

    #include<iostream>
    using namespace std;
    int
    main()
    {

        //freopen("C:\Users\Sky\Desktop\1.in","r",stdin);//PLEASE DELETE IT!!!!!!!!!!!!!!!!!!!!!!!!
        int a[350],b[350],i,j,k,n;
        while
    (cin>>n&&n)
        {

            for
    (i=0; i<=n; i++)
            {

                a[i]=1;
                b[i]=0;
            }

            for
    (i=2; i<=17; i++)
            {

                for
    (j=0; j<=n; j++)
                    for
    (k=0; k+j<=n; k+=i*i)
                        b[k+j]+=a[j];
                for
    (j=0; j<=n; j++)
                {

                    a[j]=b[j];
                    b[j]=0;
                }
            }

            cout<<a[n]<<' ';
        }

        return
    0;
    }

    HDU2152

    #include<stdio.h>
    #include<string.h>
    const int N=102;
    int min[N],max[N],c1[N],c2[N];
    int main()
    {
    	int n,m;
    	while(scanf("%d%d",&n,&m)==2)
    	{
    		int sum=0;
    		for(int i=0;i<n;i++)
    		{
    			scanf("%d%d",&min[i],&max[i]);
    			sum+=max[i];
    		}
    		for(int i=0;i<=m;i++)
    			c1[i]=c2[i]=0;
    		c1[0]=1;
    		for(int i=0;i<n;i++)
    		{
    			for(int j=0;j<=sum;j++)
    				for(int k=min[i];j+k<=m&&k<=max[i];k++)
    					c2[j+k]+=c1[j];
    			for(int i=0;i<=m;i++)
    				c1[i]=c2[i],c2[i]=0;
    		}
    		printf("%d
    ",c1[m]);
    	}
    	return 0;
    }

     HDU2189  这里不同的数存在了prime里即素数组合数

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <cstdlib>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <cassert>
    11 #include <set>
    12 #include <sstream>
    13 #include <map>
    14 using namespace std ;
    15 #ifdef DeBUG
    16 #define bug assert
    17 #else
    18 #define bug //
    19 #endif
    20 #define zero {0}
    21 #define INF 2000000000
    22 #define eps 1e-6
    23 bool num[151];
    24 int prime[40];
    25 int c1[151],c2[151];
    26 int len;
    27 void init()
    28 {
    29     int i,j;
    30     num[0]=1;
    31     num[1]=1;
    32     for(i=2;i<=150;i++)
    33     for(j=i*i;j<=150;j+=i)
    34     num[j]=1;
    35     for(i=2;i<=150;i++)
    36     if(!num[i])
    37     prime[len++]=i;
    38 }
    39 int main()
    40 {
    41     #ifdef DeBUG
    42         freopen("C:\Users\Sky\Desktop\1.in","r",stdin);
    43     #endif
    44     init();
    45     int i,j,k;
    46     for(i=0;i<=150;i+=2)
    47     {
    48         c1[i]=1;
    49         c2[i]=0;
    50     }
    51     for(i=1;i<=34;i++)
    52     {
    53         for(j=0;j<=150;j++)
    54         for(k=0;k+j<=150;k+=prime[i])
    55         c2[j+k]+=c1[j];
    56         for(j=0;j<=150;j++)
    57         {
    58             c1[j]=c2[j];
    59             c2[j]=0;
    60         }
    61     }
    62     scanf("%d",&i);
    63     while(i--)
    64     {
    65         scanf("%d",&k);
    66         printf("%d
    ",c1[k]);
    67     }
    68     
    69     return 0;
    70 }
    View Code
  • 相关阅读:
    在QT Assistant中添加帮助文档
    虚拟机下不能运行gazebo
    双系统Ubuntu无法访问Windows磁盘分区解决方法
    hexo双线部署及分流
    Apple Tree POJ
    ZOJ 3604 Tunnel Network(凯莱定理)
    C. Neko does Maths(数论 二进制枚举因数)
    Tree Cutting POJ
    Strategic game POJ
    Anniversary party POJ
  • 原文地址:https://www.cnblogs.com/Skyxj/p/3212456.html
Copyright © 2011-2022 走看看