题意:在0~(n-1)中选择k个数,使得他们的和为n的倍数的选择方案有多少种。(n <= 1000, k <= 47)

解法:裸dp。d[i][j][k’]表示在前i个数中(0~i-1),选择k‘个数使得其和mod n的余数为j的选择方案的种数。时间、空间复杂度均为O(n^2*k),时间复杂度能接受,空间不能,用滚动数组优化即可。

tag:dp, 水题

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "TheCowDivTwo.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define CLR(x) memset(x, 0, sizeof(x))
#define PB push_back
#define SZ(v) ((int)(v).size())
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int maxint = ;
const int mod = ; int d[][][]; class TheCowDivTwo
{
public:
int find(int n, int K){
CLR (d);
d[][][] = ;
int cur = ;
for (int i = ; i <= n; ++ i){
for (int j = ; j < n; ++ j){
int tmp = j-(i-)< ? n+j-(i-) : j-(i-);
for (int k = ; k <= K; ++ k){
d[cur][j][k] = d[cur^][j][k];
if (k){
d[cur][j][k] = (d[cur][j][k] + d[cur^][tmp][k-]) % mod;
}
}
}
cur ^= ;
} return d[cur^][][K];
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, find(Arg0, Arg1)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, find(Arg0, Arg1)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, find(Arg0, Arg1)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, find(Arg0, Arg1)); }
void test_case_4() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, find(Arg0, Arg1)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
TheCowDivTwo ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 502(2-1000pt)的更多相关文章

  1. SRM 502 DIV1 500pt(DP)

    题目简述 给定比赛时间T和n个题目,你可以在任意时间提交题目,每个题目有一个初始分数maxPoints[i],每个单位时间题目的分数将会减少pointsPerMinute[i],即如果在时间t解决了第 ...

  2. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

  3. TC250专场

    SRM 623 DIV2 1000pt 题意:给出一个最多50*50的矩阵,每个单元可能为'.'.'P'.'A','.'代表空地,你每次操作可以把一个P或者A拿到空地上,求一个最大的含有相同字符的矩形 ...

  4. SRM149 - SRM150(少SRM150-DIV1-LV3)

    SRM 149 DIV2 1000pt 题意: 对于n个人,第i人有pi的钱.将他们分成不超过四个组,每组统一交费x,对每个人,若他拥有的钱超过x则交费,否则不交费.问最多能使这些人交多少钱. 1&l ...

  5. Topcoder 好题推荐

    SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...

  6. SRM144 - SRM 148(少144-DIV1-LV3,147-DIV2-LV3)

    SRM 144 DIV 1 500pt tag:组合 题意:彩票中奖.给定n, m,从1-n中选择m个数组成数列a1, a2, a3...am.对于数列{am}分别满足以下条件的概率: (1)数列所有 ...

  7. SRM 508(2-1000pt)

    DIV2 1000pt 题意:给定整数n和r,求有多少个这样的数列,a1,a2...an,使得a1 + a2 +...+an = a1|a2|a3|...|an,(按位或).输出这样数列的个数mod  ...

  8. 记一次nginx部署yii2项目时502 bad gateway错误的排查

    周六闲来无事,就试着安装和部署下yii2,安装过程没什么问题,但部署到nginx上时遇到了502 bad gatewary问题,折腾了半天才搞定.这个问题是我以前在部署yii2时没有遇到过的,因此记在 ...

  9. 502 Bad Gateway深究

    早上收到502报警,设置的报警规则是502错误两分钟超过500就报警. 排障流程: 日志分析系统报障-->查看日志系统日志-->nginx错误日志-->php错误日志-->ph ...

随机推荐

  1. 关于SQL IO的一些资料

      前些天在做优化的时候发现一个有意思的现象,单纯的SQL执行很快,秒级返回,但是页面响应却很慢,一直在想这是为什么呢?有点怀疑服务器的IO有问题,想了想做了个实验,模拟了同样的场景,通过优化SQL将 ...

  2. 玩转CSLA.NET小技巧系列一:跳转页面丢失session,如何解决

    很少写代码,最近在写代码被登录难倒了,这丫的一直在跟我较劲 每次登录完跳转到首页后还是未登录状态 if (ModelState.IsValid) { bool isSuccess = FI.Finan ...

  3. IOS 多线程,线程同步的三种方式

    本文主要是讲述 IOS 多线程,线程同步的三种方式,更多IOS技术知识,请登陆疯狂软件教育官网. 一般情况下我们使用线程,在多个线程共同访问同一块资源.为保护线程资源的安全和线程访问的正确性. 在IO ...

  4. 基于ProGuard-Maven-Plugin的自定义代码混淆插件

    介绍 大家可能都会碰到一些代码比较敏感的项目场景,这个时候代码被反编译看到就不好了,这个时候就需要代码混淆插件来对代码进行混淆了. 基于Maven的项目一般会去考虑使用proguard-maven-p ...

  5. CSS3的过渡效果(transition)与动画(animation)

    1.Transition Transition是一种直观上的效果,让DOM元素的某个属性在固定时间内从一旧值到一新值.目前Firefox.Opera.Safari和Chrome都支持transitio ...

  6. C#编程连接数据库,通过更改配置文件切换数据库功能。

           该实例主要应用情景:假如某公司用mysql当做数据库服务器,由于发现mysql数据库在运行中出现不稳定情况,针对这情况,厂家要求更换连接数据库方式,改用SQL server数据库,来满足 ...

  7. 页面点击关闭弹出提示js代码

    代码效果为: <script> window.onbeforeunload = function() { return "您好!\n我是abc\n —————————————— ...

  8. PHP常用代码段:

    1.PHP加密解密   function encryptDecrypt($key, $string, $decrypt){      if($decrypt){          $decrypted ...

  9. Why is 0[0] syntactically valid in javascript?

    Why is 0[0] syntactically valid in javascript? 原文链接 偶然在一篇帖子中看到了这个问题,所以打算记录一下. var a = 0[0]; console. ...

  10. 如何在Android Studio中使用Gradle发布项目至Jcenter仓库

    简述 目前非常流行将开源库上传至Jcenter仓库中,使用起来非常方便且易于维护,特别是在Android Studio环境中,只需几步配置就可以轻松实现上传和发布. Library的转换和引用 博主的 ...