usaco_subset.cpp

来自「usaco自己做的1到5章的代码」· C++ 代码 · 共 35 行

CPP
35
字号
/*
ID: wangyuc2
PROG: subset
LANG: C++
*/ 
#include <fstream>
#include <iostream>
#include <memory>
#include <algorithm>
using namespace std;

ifstream fin("subset.in");
ofstream fout("subset.out");

int main()
{
   int i,j,m,n;
   long long a[400];
   fin>>n;
   m=n*(n+1)/2;
   if(m%2 == 1) {fout<<0<<endl; return 0;}
   m/=2;
   memset(a,0,sizeof(a));
   a[0]=1;
   for(i=1;i<=n;i++)
     for(j=m-i;j>=0;j--)
       a[j+i]+=a[j];
   fout<<a[m]/2<<endl;
   //system("PAUSE");
   return 0;
}

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?