bzoj1643 [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
2014-07-24 23:06
435 查看
Description
农夫约翰已经从他的牧场中取得了数不清块数的正方形草皮,草皮的边长总是整数(有时农夫约翰割草皮的刀法不合适,甚至切出了边长为0的正方形草皮),他已经把草皮放在了一个奶牛贝茜已经知道的地方。 贝茜总是希望把美味的草皮放到她的秘密庄园里,她决定从这些草皮中取出恰好4块搬到她的秘密庄园中,然后把它们分成1×1的小块,组成一个面积为N(1<=N<=10,000)个单位面积的部分。贝茜对选出这样四块草皮的方法数很感兴趣,如果她得到了一个4个单位面积的部分,那么她可以有5中不同的方法选4块草皮:(1,1,1,1),(2,0,0,0),(0,2,0,0),(0,0,0,2).顺序是有效的:(4,3,2,1)和(1,2,3,4)是不同的方法。
Input
第一行:一个单独的整数N。Output
单独的一行包含一个整数,表示贝茜选四块草皮的方案数。Sample Input
4Sample Output
5一道比较好想的dp
f[i][j]表示和为i、分为j份的方案数
因为是正方形,枚举它的大小
f[i][j]=Σf[i - k*k][j-1]
最后f
[1]+f
[2]+f
[3]+f
[4]即是所求
#include<cstdio> int n; int f[10010][5]; int main() { scanf("%d",&n); f[0][0]=1; for(int i=1;i<=n;i++) for (int j=1;j<=4;j++) for (int k=0;k*k<=i;k++) f[i][j]+=f[i-k*k][j-1]; printf("%d",f [1]+f [2]+f [3]+f [4]); }
相关文章推荐
- bzoj 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪(DP)
- BZOJ 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- 【BZOJ1643】[Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪【暴力】
- bzoj1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- [bzoj1643][Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- 【BZOJ】1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪(dp)
- 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- bzoj1643 [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- bzoj 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪【枚举】
- 【枚举】bzoj1643 [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- BZOJ 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- 1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
- bzoj3407 [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题
- bzoj 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题(DP)
- BZOJ 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题 背包dp
- bzoj 3393 && bzoj 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课(BFS)
- 【BZOJ3407】[Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题【01背包】
- BZOJ 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题( dp )
- BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币( dp )