【BZOJ 1025】[SCOI2009] 游戏

链接

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1025
神犇题解:http://blog.csdn.net/PoPoQQQ/article/details/40537227

解题报告

这题把数学模型抽象出来就是
取一些数ai,要求∑ai<=n
求这些数的最小公倍数有多少种不同的可能

我自己就只想到这里就想不出来了…
果然还是得膜拜神犇…

逆向考虑:考虑一个数能否被凑出来
假如将其质因数分解之后为:p1^c1 * p2 ^ c2 * …… * px^cx
并且∑pi^ci <= n,那么一定可以凑出来
考虑最小公倍数的定义:至少有一个数中包含了pi^ci
所以这样判断是没有问题的

于是从小到大考虑质因数,使用分组背包进行转移
f[i][j]表示已经考虑了前i个质数,\(\sum\limits_{k = 1}^i {p_k^{{c_k}}} = j\)
时间复杂度O(n^2)

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 1000+9;

LL n,tot,pri[N],vout,f[N][N];

inline int read(){
	char c=getchar(); int ret=0,f=1;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret*f;
}

inline void prework() {
	for (int i=2;i<=n;i++) {
		bool tag = 1;
		for (int j=2;j<i;j++) {
			if (i % j == 0) {
				tag = 0;
				break;
			}
		}
		if (tag) {
			pri[++tot] = i;
		}
	}
	f[0][0] = 1;
}

int main(){
	n = read();
	prework();
	for (int i=1;i<=tot;i++) {
		for (int j=0;j<=n;j++) {
			f[i][j] += f[i-1][j];
			for (int k=pri[i];k<=j;k*=pri[i]) {
				f[i][j] += f[i-1][j-k];
			}
		}
	}
	for (int i=0;i<=n;i++) 
		vout += f[tot][i];
	printf("%lld\n",vout);
	return 0;
}

18 thoughts to “【BZOJ 1025】[SCOI2009] 游戏”

  1. 948249 406090Average In turn sends provides may be the frequent systems that give the opportunity for ones how does a person pick-up biological, overdue drivers, what one mechanically increases the business. Search Engine Marketing 31996

  2. 358279 388965An fascinating discussion may be valued at comment. I do believe which you basically write read much more about this subject, it may not often be a taboo topic but normally persons are too couple of to dicuss on such topics. To a higher. Cheers 496621

  3. 259795 294920This is a excellent blog, would you be involved in performing an interview about just how you designed it? If so e-mail me! 993708

  4. 948448 319944Hello! I just wish to give an enormous thumbs up for the very good details you may have right here on this post. I can be coming once more to your blog for far more soon. 210450

  5. Prior to becoming a member of an illusion baseball league, make sure you are absolutely committed. You can’t give up the league at the center. You can not be there at the start and after that cease to the midsection. Stopping could have a negative influence on the drafting together with other players’ impression people.

  6. Play with your own style. You shouldn’t commit the game upstaging your teammates or thinking of just you, but there are actually moment within a soccer game where your individuality can stand out, especially soon after a remarkable deal with or touchdown. Do you have a specific fist push or shuffle party you would like to take out. Do it! Get the teammates involved as well.

  7. Even should you not play in every single game, study the playbook every day. Anytime you do have a free min, check out the performs. You need to anticipate to get tossed into the video game whenever you want. Who knows when a person can get hurt or even your instructor desires to provide the chance to perform. Learning the performs will prevent you from hunting foolish on the field.

  8. Exercise all you could. Football might appear straightforward when watching it on tv, but that’s far from the reality. It’s a very actually stressful activity which get a great deal of human brain energy. You have to keep in mind habits and think in your toes with little recognize to be successful. All this takes exercise.

  9. Understand by watching the advantages. This doesn’t mean just seated around and finding this game along with your friends. Get a gamer who plays the identical place as you may and enjoy the direction they play. Analyze the way that they relocate their feet, and what selections they make in the area. Make an effort to replicate them in your own online game.

Leave a Reply

Your email address will not be published. Required fields are marked *