245 条题解
-
0linhui LV 9 @ 2015-10-08 10:28:29
#include<cstdio>
using namespace std;
int f[300][10];
int main()
{
int n, k;
scanf("%d%d", &n, &k);
for(int i=1; i<=n; i++){
f[i][1] = 1;
for(int j=2; j<=i&&j<=k; j++) f[i][j] = f[i-1][j-1] + f[i-j][j];
}
printf("%d", f[n][k]);
return 0;
}
水一发~14行 -
02015-08-30 11:13:44@
#include<iostream>
#include<cstdio>
using namespace std;
int f[201][7],n,k;
int main()
{
scanf("%d%d",&n,&k);
f[1][1]=1;
for(int i=1;i<=n;i++)
for(int j=2;j<=k&&j<=i;j++){
f[i][1]=1;
f[i][j]=f[i-1][j-1]+f[i-j][j];
}
printf("%d",f[n][k]);
} -
02015-06-30 11:13:35@
DP我不会,我的做法是这样的,把此题假想成:n块蛋糕放入k个篮子。因为不能有空,一开始k个篮子都有1块蛋糕,然后每一次可以将j~n篮子内都加1块蛋糕(1<=j<=n),如果这样做,下一次加的时候只能从j或比j大的篮子里开始加(防止重复放法),刚好放完n块蛋糕则为一种方法。
剪枝:j的循环从大到小,某一次放蛋糕后若蛋糕总数>n或无法放蛋糕,则更小的j不用考虑(因为j越小要放的越多)
#include<stdio.h>
int n,k,ans=0;int search(int count,int start)
{
int i;if(count==n) {ans++;return 1;}
else if(count>n) return 0;
for(i=k;i>=start;i--)
if(search(count+k-i+1,i)==0) break;if(i==k) return 0;
else return 1;
}int main( )
{
scanf("%d %d",&n,&k);if(search(k,1));
printf("%d",ans);
} -
02015-03-27 13:37:38@
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<time.h>
#include<stdlib.h>
using namespace std;
int g[203][203];
int f(int n, int k){
if (n < k)return 0;
if (g[n][k] == -1){
if (k == 1)return 1;
g[n][k] = f(n - 1, k - 1) + f(n - k, k);
}
return g[n][k];
}
int main(){
freopen("in.txt", "r", stdin);
int n,k;
memset(g, -1, sizeof(g));
cin >> n >> k;
cout << f(n, k) << endl;
return 0;
} -
02015-03-16 14:08:45@
#include <iostream>
using namespace std;
int fal[201][7];
int main(){
int n, k;
cin >> n >> k;
fal[0][0] = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= k; j++){
if (i >= j){
fal[i][j] = fal[i - j][j] + fal[i - 1][j - 1];
}
}
}
cout << fal[n][k] << endl;}
DP完解
问题分成两种情况:有1和没有1
有1的情况,拿出一个1,然后把剩下的n-1分成k-1份,即fal[n-1][k-1]
没有1的情况,拿出k个1,然后把剩下的n-k分成k份,即fal[n-k][k] -
02015-01-01 23:43:02@
//递归法
#include<iostream>
#include<cstdio>
using namespace std;
int ser(int ,int, int);
int main()
{
int n,k;
cin>>n>>k;
cout<<ser(n,k,1);//从1开始拆,避免重复
return 0;
}int ser(int a,int b,int c)
{
int g=0; //拆分方案数
if(b==1)
/*此时已经确定,因为b==1,只有一种可能,就是总数减去前几个数,不涉及前几个数已经超出总数的可能,因为下面的for循环已保证*/
g=1;
if(b>1)
{
/*思路解释:题目中已经强调重复的情况不算 ,因此只要保证拆的数由小到大
即可,在for循环中让起始值与上一次拆分已经确定的值相等,最大值为a/b,
以样例为例:7/3=2;若第二位数大于2,为3,至少是3,3,3已经超了7.所以第
一位必然是1或2*/
for(int i=c;i<=a/b;i++)
{
g=g+ser(a-i,b-1,i);//ser(总数字大小,需要拆的位数(控制着循环次数),从第几个数开始拆)递归
}
}
return g; //返回值
} -
02014-11-04 22:09:05@
谁的程序比我短?????
#include<cstdio>
int a[201][7],n,k;
int main()
{
scanf("%d%d",&n,&k);
a[0][0]=1;
for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) if(i>=j) a[i][j]=a[i-1][j-1]+a[i-j][j];
printf("%d",a[n][k]);
return 0;
} -
02014-10-24 07:54:06@
补充:x[i][j]表示把i分为j种的状态
动态转移方程:x[i][j]=x[i-1][j-1]+x[i-j][j];
因为每个解只有含1与不含1两种情况,含1的情况与把这个数减去1(分解时就没有a1了),再分解为j-1个(a2,a3...aj)的情况个数相同
不含1的情况把每个数(a1,a2...aj)减去1(a1-1,a2-1...aj-1),则j不变,要分解的数为i-1-1...-1=i-j -
02014-10-24 00:08:50@
动态规划的思想(综合楼下各位大神题解,个人认为写的比较清晰,C++代码)
先鄙视一下数据(真大,专为DFS设计),再鄙视一下O(1)的算法……
* 评测状态 Accepted
* 题目 P1117 数的划分
* 递交时间 2014-10-23 23:49:03
* 代码语言 C++
* 评测机 上海红茶馆
* 消耗时间 15 ms
* 消耗内存 560 KiB
* 评测时间 2014-10-23 23:49:04
** 评测结果 **
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 20
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 20
测试数据 #2: Accepted, time = 15 ms, mem = 560 KiB, score = 20
测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 20
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 20
Accepted, time = 15 ms, mem = 560 KiB, score = 100int x[200][10];
int main()
{
//freopen("p1117.in","r",stdin);
//freopen("p1117.out","w",stdout);
x[1][1]=1;
int n,k;
scanf("%d%d",&n,&k);
for(int i=2;i<=n;i++)
{
x[i][1]=1;
for(int j=2;(j<=k) && (j<=i);j++)
x[i][j]=x[i-1][j-1]+x[i-j][j];
}
printf("%d",x[n][k]);
return 0;
}
对于x[i][j],有两种情况:
设x[i][j]=a1+a2+...+aj(0<a1<=a2<=...<=aj)
1.a1=1 转换为x[i-1(去掉开头的1)][j-1(因此分解出的个数少一种)]
2.a1!=1 转换为x[i-j(注释)][j(个数不变)]
注释: i=(a1-1)+1+(a2-1)+1+(a3-1)+1+……+(aj-1)+1= j+(a1-1)+(a2-1)+(a3-1)+……+(aj-1) -
02014-10-23 21:18:22@
#include <iostream>
using namespace std;
int N,K;
long long d[200+50][10][200+50];
int vis[200+50][10][200+50];
long long dp(int,int,int);
int main()
{
cin>>N>>K;
cout<<dp(N,K,1)<<endl;
return 0;}
long long dp(int i,int j,int k)
{
if(j==1) return 1;
if(vis[i][j][k]==1) return d[i][j][k];
vis[i][j][k]=1;
long long &ans=d[i][j][k];
for(int p=k;p<=i;++p)
if(i-p>=0&&i-p>=p)
ans+=dp(i-p,j-1,p);
return ans;
} -
02014-10-20 20:10:37@
program xxxx;
var g,i,j,k,n,m:longint;function f(x,y,z:longint):longint;
var g,i:longint;
begin
g:=0;
if y=1 then g:=1
else
for i:=z to trunc(x/y) do
g:=g+f(x-i,y-1,i);
f:=g;
end;begin
readln(n,k);
writeln(f(n,k,1));
end.其实没搞懂为什么把function里的var 删掉就cuo
-
02014-10-20 19:58:34@
program xxx;
var i,j,k,n,m,x,tt:longint;
a:array[0..100001] of longint;
b:array[0..100001] of boolean;procedure datain;
var i,j,tt,n1:longint;
begin
readln(n,k);
a[1]:=0;
tt:=0;
i:=1;
while i>0 do
begin
inc(a[i]);
n1:=n;
for j:=1 to i-1 do
n1:=n1-a[j];
if a[i]>n1 then
dec(i) else if i=k then
begin
x:=0;
for j:=1 to k do
begin
x:=a[j]+x;
end;
if x=n then inc(tt);
end else
begin
inc(i);
a[i]:=a[i-1]-1;
end;
end;
writeln(tt);
end;begin
datain;
end.
只有八十。。果然回溯就是菜 -
02014-07-21 19:12:08@
水题一道————3分钟解决
program P1117;
uses Math;
var
n,k : integer;function Find(i,m,s:integer):longint;
var
j,u,ans : longint;
begin
if i = k then exit(1);
ans := 0;
u := floor(m / (k - i + 1));
for j := s to u do
inc(ans, Find(i+1, m - j, j));
exit(ans);
end;begin
readln(n, k);
writeln(Find(1, n, 1));
end. -
02014-02-27 21:55:23@
f[1,1]:=1;
for i:=2 to n do begin
f[i,1]:=1;
for j:=2 to k do
if i>=j then
f[i,j]:=f[i-1,j-1]+f[i-j,j];
end;
题解:f[i,j]=f[i-1,j-1]+f[i-j,j]
f[i-1,j]:很容易想到把n分成k个可以先把1单独做一组,然后n-1分成k-1份
f[i- j,j]:
(某学霸给出的证明:)
i=a1+a2+a3+……+aj ,a1<=a2<=a3<=……aj;
=j+(a1-1)+(a2-1)+(a3-1)+……+(aj-1)
∴ i-j=(a1-1)+(a2-1)+(a3-1)+……+(aj-1) //也就是把n-j划分为k这种情况
所以f[i,j]也有f[i-j,j]这种状态。
所以就把两个东西加起来就可以…… -
02013-10-25 16:51:09@
打表无压力……
f[6,2]:=3;
f[6,3]:=3;
f[6,4]:=2;
f[6,5]:=1;
f[6,6]:=1;
f[7,2]:=3;
f[7,3]:=4;
f[7,4]:=3;
f[7,5]:=2;
f[7,6]:=1;
f[8,2]:=4;
f[8,3]:=5;
f[8,4]:=5;
f[8,5]:=3;
f[8,6]:=2;
f[9,2]:=4;
f[9,3]:=7;
f[9,4]:=6;
f[9,5]:=5;
f[9,6]:=3;
f[10,2]:=5;
f[10,3]:=8;
f[10,4]:=9;
f[10,5]:=7;
f[10,6]:=5;
f[11,2]:=5;
f[11,3]:=10;
f[11,4]:=11;
f[11,5]:=10;
f[11,6]:=7;
f[12,2]:=6;
f[12,3]:=12;
f[12,4]:=15;
f[12,5]:=13;
f[12,6]:=11;
f[13,2]:=6;
f[13,3]:=14;
f[13,4]:=18;
f[13,5]:=18;
f[13,6]:=14;
f[14,2]:=7;
f[14,3]:=16;
f[14,4]:=23;
f[14,5]:=23;
f[14,6]:=20;
f[15,2]:=7;
f[15,3]:=19;
f[15,4]:=27;
f[15,5]:=30;
f[15,6]:=26;
f[16,2]:=8;
f[16,3]:=21;
f[16,4]:=34;
f[16,5]:=37;
f[16,6]:=35;
f[17,2]:=8;
f[17,3]:=24;
f[17,4]:=39;
f[17,5]:=47;
f[17,6]:=44;
f[18,2]:=9;
f[18,3]:=27;
f[18,4]:=47;
f[18,5]:=57;
f[18,6]:=58;
f[19,2]:=9;
f[19,3]:=30;
f[19,4]:=54;
f[19,5]:=70;
f[19,6]:=71;
f[20,2]:=10;
f[20,3]:=33;
f[20,4]:=64;
f[20,5]:=84;
f[20,6]:=90;
f[21,2]:=10;
f[21,3]:=37;
f[21,4]:=72;
f[21,5]:=101;
f[21,6]:=110;
f[22,2]:=11;
f[22,3]:=40;
f[22,4]:=84;
f[22,5]:=119;
f[22,6]:=136;
f[23,2]:=11;
f[23,3]:=44;
f[23,4]:=94;
f[23,5]:=141;
f[23,6]:=163;
f[24,2]:=12;
f[24,3]:=48;
f[24,4]:=108;
f[24,5]:=164;
f[24,6]:=199;
f[25,2]:=12;
f[25,3]:=52;
f[25,4]:=120;
f[25,5]:=192;
f[25,6]:=235;
f[26,2]:=13;
f[26,3]:=56;
f[26,4]:=136;
f[26,5]:=221;
f[26,6]:=282;
f[27,2]:=13;
f[27,3]:=61;
f[27,4]:=150;
f[27,5]:=255;
f[27,6]:=331;
f[28,2]:=14;
f[28,3]:=65;
f[28,4]:=169;
f[28,5]:=291;
f[28,6]:=391;
f[29,2]:=14;
f[29,3]:=70;
f[29,4]:=185;
f[29,5]:=333;
f[29,6]:=454;
f[30,2]:=15;
f[30,3]:=75;
f[30,4]:=206;
f[30,5]:=377;
f[30,6]:=532;
f[31,2]:=15;
f[31,3]:=80;
f[31,4]:=225;
f[31,5]:=427;
f[31,6]:=612;
f[32,2]:=16;
f[32,3]:=85;
f[32,4]:=249;
f[32,5]:=480;
f[32,6]:=709;
f[33,2]:=16;
f[33,3]:=91;
f[33,4]:=270;
f[33,5]:=540;
f[33,6]:=811;
f[34,2]:=17;
f[34,3]:=96;
f[34,4]:=297;
f[34,5]:=603;
f[34,6]:=931;
f[35,2]:=17;
f[35,3]:=102;
f[35,4]:=321;
f[35,5]:=674;
f[35,6]:=1057;
f[36,2]:=18;
f[36,3]:=108;
f[36,4]:=351;
f[36,5]:=748;
f[36,6]:=1206;
f[37,2]:=18;
f[37,3]:=114;
f[37,4]:=378;
f[37,5]:=831;
f[37,6]:=1360;
f[38,2]:=19;
f[38,3]:=120;
f[38,4]:=411;
f[38,5]:=918;
f[38,6]:=1540;
f[39,2]:=19;
f[39,3]:=127;
f[39,4]:=441;
f[39,5]:=1014;
f[39,6]:=1729;
f[40,2]:=20;
f[40,3]:=133;
f[40,4]:=478;
f[40,5]:=1115;
f[40,6]:=1945;
f[41,2]:=20;
f[41,3]:=140;
f[41,4]:=511;
f[41,5]:=1226;
f[41,6]:=2172;
f[42,2]:=21;
f[42,3]:=147;
f[42,4]:=551;
f[42,5]:=1342;
f[42,6]:=2432;
f[43,2]:=21;
f[43,3]:=154;
f[43,4]:=588;
f[43,5]:=1469;
f[43,6]:=2702;
f[44,2]:=22;
f[44,3]:=161;
f[44,4]:=632;
f[44,5]:=1602;
f[44,6]:=3009;
f[45,2]:=22;
f[45,3]:=169;
f[45,4]:=672;
f[45,5]:=1747;
f[45,6]:=3331;
f[46,2]:=23;
f[46,3]:=176;
f[46,4]:=720;
f[46,5]:=1898;
f[46,6]:=3692;
f[47,2]:=23;
f[47,3]:=184;
f[47,4]:=764;
f[47,5]:=2062;
f[47,6]:=4070;
f[48,2]:=24;
f[48,3]:=192;
f[48,4]:=816;
f[48,5]:=2233;
f[48,6]:=4494;
f[49,2]:=24;
f[49,3]:=200;
f[49,4]:=864;
f[49,5]:=2418;
f[49,6]:=4935;
f[50,2]:=25;
f[50,3]:=208;
f[50,4]:=920;
f[50,5]:=2611;
f[50,6]:=5427;
f[51,2]:=25;
f[51,3]:=217;
f[51,4]:=972;
f[51,5]:=2818;
f[51,6]:=5942;
f[52,2]:=26;
f[52,3]:=225;
f[52,4]:=1033;
f[52,5]:=3034;
f[52,6]:=6510;
f[53,2]:=26;
f[53,3]:=234;
f[53,4]:=1089;
f[53,5]:=3266;
f[53,6]:=7104;
f[54,2]:=27;
f[54,3]:=243;
f[54,4]:=1154;
f[54,5]:=3507;
f[54,6]:=7760;
f[55,2]:=27;
f[55,3]:=252;
f[55,4]:=1215;
f[55,5]:=3765;
f[55,6]:=8442;
f[56,2]:=28;
f[56,3]:=261;
f[56,4]:=1285;
f[56,5]:=4033;
f[56,6]:=9192;
f[57,2]:=28;
f[57,3]:=271;
f[57,4]:=1350;
f[57,5]:=4319;
f[57,6]:=9975;
f[58,2]:=29;
f[58,3]:=280;
f[58,4]:=1425;
f[58,5]:=4616;
f[58,6]:=10829;
f[59,2]:=29;
f[59,3]:=290;
f[59,4]:=1495;
f[59,5]:=4932;
f[59,6]:=11720;
f[60,2]:=30;
f[60,3]:=300;
f[60,4]:=1575;
f[60,5]:=5260;
f[60,6]:=12692;
f[61,2]:=30;
f[61,3]:=310;
f[61,4]:=1650;
f[61,5]:=5608;
f[61,6]:=13702;
f[62,2]:=31;
f[62,3]:=320;
f[62,4]:=1735;
f[62,5]:=5969;
f[62,6]:=14800;
f[63,2]:=31;
f[63,3]:=331;
f[63,4]:=1815;
f[63,5]:=6351;
f[63,6]:=15944;
f[64,2]:=32;
f[64,3]:=341;
f[64,4]:=1906;
f[64,5]:=6747;
f[64,6]:=17180;
f[65,2]:=32;
f[65,3]:=352;
f[65,4]:=1991;
f[65,5]:=7166;
f[65,6]:=18467;
f[66,2]:=33;
f[66,3]:=363;
f[66,4]:=2087;
f[66,5]:=7599;
f[66,6]:=19858;
f[67,2]:=33;
f[67,3]:=374;
f[67,4]:=2178;
f[67,5]:=8056;
f[67,6]:=21301;
f[68,2]:=34;
f[68,3]:=385;
f[68,4]:=2280;
f[68,5]:=8529;
f[68,6]:=22856;
f[69,2]:=34;
f[69,3]:=397;
f[69,4]:=2376;
f[69,5]:=9027;
f[69,6]:=24473;
f[70,2]:=35;
f[70,3]:=408;
f[70,4]:=2484;
f[70,5]:=9542;
f[70,6]:=26207;
f[71,2]:=35;
f[71,3]:=420;
f[71,4]:=2586;
f[71,5]:=10083;
f[71,6]:=28009;
f[72,2]:=36;
f[72,3]:=432;
f[72,4]:=2700;
f[72,5]:=10642;
f[72,6]:=29941;
f[73,2]:=36;
f[73,3]:=444;
f[73,4]:=2808;
f[73,5]:=11229;
f[73,6]:=31943;
f[74,2]:=37;
f[74,3]:=456;
f[74,4]:=2928;
f[74,5]:=11835;
f[74,6]:=34085;
f[75,2]:=37;
f[75,3]:=469;
f[75,4]:=3042;
f[75,5]:=12470;
f[75,6]:=36308;
f[76,2]:=38;
f[76,3]:=481;
f[76,4]:=3169;
f[76,5]:=13125;
f[76,6]:=38677;
f[77,2]:=38;
f[77,3]:=494;
f[77,4]:=3289;
f[77,5]:=13811;
f[77,6]:=41134;
f[78,2]:=39;
f[78,3]:=507;
f[78,4]:=3422;
f[78,5]:=14518;
f[78,6]:=43752;
f[79,2]:=39;
f[79,3]:=520;
f[79,4]:=3549;
f[79,5]:=15257;
f[79,6]:=46461;
f[80,2]:=40;
f[80,3]:=533;
f[80,4]:=3689;
f[80,5]:=16019;
f[80,6]:=49342;
f[81,2]:=40;
f[81,3]:=547;
f[81,4]:=3822;
f[81,5]:=16814;
f[81,6]:=52327;
f[82,2]:=41;
f[82,3]:=560;
f[82,4]:=3969;
f[82,5]:=17633;
f[82,6]:=55491;
f[83,2]:=41;
f[83,3]:=574;
f[83,4]:=4109;
f[83,5]:=18487;
f[83,6]:=58767;
f[84,2]:=42;
f[84,3]:=588;
f[84,4]:=4263;
f[84,5]:=19366;
f[84,6]:=62239;
f[85,2]:=42;
f[85,3]:=602;
f[85,4]:=4410;
f[85,5]:=20282;
f[85,6]:=65827;
f[86,2]:=43;
f[86,3]:=616;
f[86,4]:=4571;
f[86,5]:=21224;
f[86,6]:=69624;
f[87,2]:=43;
f[87,3]:=631;
f[87,4]:=4725;
f[87,5]:=22204;
f[87,6]:=73551;
f[88,2]:=44;
f[88,3]:=645;
f[88,4]:=4894;
f[88,5]:=23212;
f[88,6]:=77695;
f[89,2]:=44;
f[89,3]:=660;
f[89,4]:=5055;
f[89,5]:=24260;
f[89,6]:=81979;
f[90,2]:=45;
f[90,3]:=675;
f[90,4]:=5231;
f[90,5]:=25337;
f[90,6]:=86499;
f[91,2]:=45;
f[91,3]:=690;
f[91,4]:=5400;
f[91,5]:=26455;
f[91,6]:=91164;
f[92,2]:=46;
f[92,3]:=705;
f[92,4]:=5584;
f[92,5]:=27604;
f[92,6]:=96079;
f[93,2]:=46;
f[93,3]:=721;
f[93,4]:=5760;
f[93,5]:=28796;
f[93,6]:=101155;
f[94,2]:=47;
f[94,3]:=736;
f[94,4]:=5952;
f[94,5]:=30020;
f[94,6]:=106491;
f[95,2]:=47;
f[95,3]:=752;
f[95,4]:=6136;
f[95,5]:=31289;
f[95,6]:=111999;
f[96,2]:=48;
f[96,3]:=768;
f[96,4]:=6336;
f[96,5]:=32591;
f[96,6]:=117788;
f[97,2]:=48;
f[97,3]:=784;
f[97,4]:=6528;
f[97,5]:=33940;
f[97,6]:=123755;
f[98,2]:=49;
f[98,3]:=800;
f[98,4]:=6736;
f[98,5]:=35324;
f[98,6]:=130019;
f[99,2]:=49;
f[99,3]:=817;
f[99,4]:=6936;
f[99,5]:=36756;
f[99,6]:=136479;
f[100,2]:=50;
f[100,3]:=833;
f[100,4]:=7153;
f[100,5]:=38225;
f[100,6]:=143247;
f[101,2]:=50;
f[101,3]:=850;
f[101,4]:=7361;
f[101,5]:=39744;
f[101,6]:=150224;
f[102,2]:=51;
f[102,3]:=867;
f[102,4]:=7586;
f[102,5]:=41301;
f[102,6]:=157532;
f[103,2]:=51;
f[103,3]:=884;
f[103,4]:=7803;
f[103,5]:=42910;
f[103,6]:=165056;
f[104,2]:=52;
f[104,3]:=901;
f[104,4]:=8037;
f[104,5]:=44559;
f[104,6]:=172929;
f[105,2]:=52;
f[105,3]:=919;
f[105,4]:=8262;
f[105,5]:=46262;
f[105,6]:=181038;
f[106,2]:=53;
f[106,3]:=936;
f[106,4]:=8505;
f[106,5]:=48006;
f[106,6]:=189509;
f[107,2]:=53;
f[107,3]:=954;
f[107,4]:=8739;
f[107,5]:=49806;
f[107,6]:=198230;
f[108,2]:=54;
f[108,3]:=972;
f[108,4]:=8991;
f[108,5]:=51649;
f[108,6]:=207338;
f[109,2]:=54;
f[109,3]:=990;
f[109,4]:=9234;
f[109,5]:=53550;
f[109,6]:=216705;
f[110,2]:=55;
f[110,3]:=1008;
f[110,4]:=9495;
f[110,5]:=55496;
f[110,6]:=226479;
f[111,2]:=55;
f[111,3]:=1027;
f[111,4]:=9747;
f[111,5]:=57501;
f[111,6]:=236534;
f[112,2]:=56;
f[112,3]:=1045;
f[112,4]:=10018;
f[112,5]:=59553;
f[112,6]:=247010;
f[113,2]:=56;
f[113,3]:=1064;
f[113,4]:=10279;
f[113,5]:=61667;
f[113,6]:=257783;
f[114,2]:=57;
f[114,3]:=1083;
f[114,4]:=10559;
f[114,5]:=63829;
f[114,6]:=269005;
f[115,2]:=57;
f[115,3]:=1102;
f[115,4]:=10830;
f[115,5]:=66055;
f[115,6]:=280534;
f[116,2]:=58;
f[116,3]:=1121;
f[116,4]:=11120;
f[116,5]:=68331;
f[116,6]:=292534;
f[117,2]:=58;
f[117,3]:=1141;
f[117,4]:=11400;
f[117,5]:=70673;
f[117,6]:=304865;
f[118,2]:=59;
f[118,3]:=1160;
f[118,4]:=11700;
f[118,5]:=73067;
f[118,6]:=317683;
f[119,2]:=59;
f[119,3]:=1180;
f[119,4]:=11990;
f[119,5]:=75529;
f[119,6]:=330850;
f[120,2]:=60;
f[120,3]:=1200;
f[120,4]:=12300;
f[120,5]:=78045;
f[120,6]:=344534;
f[121,2]:=60;
f[121,3]:=1220;
f[121,4]:=12600;
f[121,5]:=80631;
f[121,6]:=358579;
f[122,2]:=61;
f[122,3]:=1240;
f[122,4]:=12920;
f[122,5]:=83273;
f[122,6]:=373165;
f[123,2]:=61;
f[123,3]:=1261;
f[123,4]:=13230;
f[123,5]:=85987;
f[123,6]:=388138;
f[124,2]:=62;
f[124,3]:=1281;
f[124,4]:=13561;
f[124,5]:=88759;
f[124,6]:=403670;
f[125,2]:=62;
f[125,3]:=1302;
f[125,4]:=13881;
f[125,5]:=91606;
f[125,6]:=419609;
f[126,2]:=63;
f[126,3]:=1323;
f[126,4]:=14222;
f[126,5]:=94512;
f[126,6]:=436140;
f[127,2]:=63;
f[127,3]:=1344;
f[127,4]:=14553;
f[127,5]:=97495;
f[127,6]:=453091;
f[128,2]:=64;
f[128,3]:=1365;
f[128,4]:=14905;
f[128,5]:=100540;
f[128,6]:=470660;
f[129,2]:=64;
f[129,3]:=1387;
f[129,4]:=15246;
f[129,5]:=103664;
f[129,6]:=488678;
f[130,2]:=65;
f[130,3]:=1408;
f[130,4]:=15609;
f[130,5]:=106852;
f[130,6]:=507334;
f[131,2]:=65;
f[131,3]:=1430;
f[131,4]:=15961;
f[131,5]:=110121;
f[131,6]:=526461;
f[132,2]:=66;
f[132,3]:=1452;
f[132,4]:=16335;
f[132,5]:=113456;
f[132,6]:=546261;
f[133,2]:=66;
f[133,3]:=1474;
f[133,4]:=16698;
f[133,5]:=116875;
f[133,6]:=566547;
f[134,2]:=67;
f[134,3]:=1496;
f[134,4]:=17083;
f[134,5]:=120362;
f[134,6]:=587535;
f[135,2]:=67;
f[135,3]:=1519;
f[135,4]:=17457;
f[135,5]:=123935;
f[135,6]:=609040;
f[136,2]:=68;
f[136,3]:=1541;
f[136,4]:=17854;
f[136,5]:=127578;
f[136,6]:=631269;
f[137,2]:=68;
f[137,3]:=1564;
f[137,4]:=18239;
f[137,5]:=131310;
f[137,6]:=654039;
f[138,2]:=69;
f[138,3]:=1587;
f[138,4]:=18647;
f[138,5]:=135114;
f[138,6]:=677571;
f[139,2]:=69;
f[139,3]:=1610;
f[139,4]:=19044;
f[139,5]:=139009;
f[139,6]:=701661;
f[140,2]:=70;
f[140,3]:=1633;
f[140,4]:=19464;
f[140,5]:=142979;
f[140,6]:=726544;
f[141,2]:=70;
f[141,3]:=1657;
f[141,4]:=19872;
f[141,5]:=147042;
f[141,6]:=752019;
f[142,2]:=71;
f[142,3]:=1680;
f[142,4]:=20304;
f[142,5]:=151182;
f[142,6]:=778311;
f[143,2]:=71;
f[143,3]:=1704;
f[143,4]:=20724;
f[143,5]:=155418;
f[143,6]:=805221;
f[144,2]:=72;
f[144,3]:=1728;
f[144,4]:=21168;
f[144,5]:=159733;
f[144,6]:=832989;
f[145,2]:=72;
f[145,3]:=1752;
f[145,4]:=21600;
f[145,5]:=164147;
f[145,6]:=861394;
f[146,2]:=73;
f[146,3]:=1776;
f[146,4]:=22056;
f[146,5]:=168642;
f[146,6]:=890691;
f[147,2]:=73;
f[147,3]:=1801;
f[147,4]:=22500;
f[147,5]:=173238;
f[147,6]:=920661;
f[148,2]:=74;
f[148,3]:=1825;
f[148,4]:=22969;
f[148,5]:=177918;
f[148,6]:=951549;
f[149,2]:=74;
f[149,3]:=1850;
f[149,4]:=23425;
f[149,5]:=182702;
f[149,6]:=983139;
f[150,2]:=75;
f[150,3]:=1875;
f[150,4]:=23906;
f[150,5]:=187572;
f[150,6]:=1015691;
f[151,2]:=75;
f[151,3]:=1900;
f[151,4]:=24375;
f[151,5]:=192548;
f[151,6]:=1048966;
f[152,2]:=76;
f[152,3]:=1925;
f[152,4]:=24869;
f[152,5]:=197613;
f[152,6]:=1083239;
f[153,2]:=76;
f[153,3]:=1951;
f[153,4]:=25350;
f[153,5]:=202787;
f[153,6]:=1118274;
f[154,2]:=77;
f[154,3]:=1976;
f[154,4]:=25857;
f[154,5]:=208052;
f[154,6]:=1154336;
f[155,2]:=77;
f[155,3]:=2002;
f[155,4]:=26351;
f[155,5]:=213429;
f[155,6]:=1191191;
f[156,2]:=78;
f[156,3]:=2028;
f[156,4]:=26871;
f[156,5]:=218899;
f[156,6]:=1229120;
f[157,2]:=78;
f[157,3]:=2054;
f[157,4]:=27378;
f[157,5]:=224484;
f[157,6]:=1267865;
f[158,2]:=79;
f[158,3]:=2080;
f[158,4]:=27911;
f[158,5]:=230165;
f[158,6]:=1307723;
f[159,2]:=79;
f[159,3]:=2107;
f[159,4]:=28431;
f[159,5]:=235963;
f[159,6]:=1348439;
f[160,2]:=80;
f[160,3]:=2133;
f[160,4]:=28978;
f[160,5]:=241860;
f[160,6]:=1390299;
f[161,2]:=80;
f[161,3]:=2160;
f[161,4]:=29511;
f[161,5]:=247877;
f[161,6]:=1433051;
f[162,2]:=81;
f[162,3]:=2187;
f[162,4]:=30071;
f[162,5]:=253995;
f[162,6]:=1476997;
f[163,2]:=81;
f[163,3]:=2214;
f[163,4]:=30618;
f[163,5]:=260236;
f[163,6]:=1521860;
f[164,2]:=82;
f[164,3]:=2241;
f[164,4]:=31192;
f[164,5]:=266581;
f[164,6]:=1567959;
f[165,2]:=82;
f[165,3]:=2269;
f[165,4]:=31752;
f[165,5]:=273052;
f[165,6]:=1615020;
f[166,2]:=83;
f[166,3]:=2296;
f[166,4]:=32340;
f[166,5]:=279629;
f[166,6]:=1663351;
f[167,2]:=83;
f[167,3]:=2324;
f[167,4]:=32914;
f[167,5]:=286335;
f[167,6]:=1712680;
f[168,2]:=84;
f[168,3]:=2352;
f[168,4]:=33516;
f[168,5]:=293150;
f[168,6]:=1763332;
f[169,2]:=84;
f[169,3]:=2380;
f[169,4]:=34104;
f[169,5]:=300097;
f[169,6]:=1815010;
f[170,2]:=85;
f[170,3]:=2408;
f[170,4]:=34720;
f[170,5]:=307156;
f[170,6]:=1868056;
f[171,2]:=85;
f[171,3]:=2437;
f[171,4]:=35322;
f[171,5]:=314349;
f[171,6]:=1922176;
f[172,2]:=86;
f[172,3]:=2465;
f[172,4]:=35953;
f[172,5]:=321657;
f[172,6]:=1977700;
f[173,2]:=86;
f[173,3]:=2494;
f[173,4]:=36569;
f[173,5]:=329103;
f[173,6]:=2034337;
f[174,2]:=87;
f[174,3]:=2523;
f[174,4]:=37214;
f[174,5]:=336666;
f[174,6]:=2092435;
f[175,2]:=87;
f[175,3]:=2552;
f[175,4]:=37845;
f[175,5]:=344370;
f[175,6]:=2151676;
f[176,2]:=88;
f[176,3]:=2581;
f[176,4]:=38505;
f[176,5]:=352194;
f[176,6]:=2212426;
f[177,2]:=88;
f[177,3]:=2611;
f[177,4]:=39150;
f[177,5]:=360162;
f[177,6]:=2274370;
f[178,2]:=89;
f[178,3]:=2640;
f[178,4]:=39825;
f[178,5]:=368253;
f[178,6]:=2337862;
f[179,2]:=89;
f[179,3]:=2670;
f[179,4]:=40485;
f[179,5]:=376491;
f[179,6]:=2402590;
f[180,2]:=90;
f[180,3]:=2700;
f[180,4]:=41175;
f[180,5]:=384855;
f[180,6]:=2468926;
f[181,2]:=90;
f[181,3]:=2730;
f[181,4]:=41850;
f[181,5]:=393369;
f[181,6]:=2536531;
f[182,2]:=91;
f[182,3]:=2760;
f[182,4]:=42555;
f[182,5]:=402012;
f[182,6]:=2605795;
f[183,2]:=91;
f[183,3]:=2791;
f[183,4]:=43245;
f[183,5]:=410808;
f[183,6]:=2676382;
f[184,2]:=92;
f[184,3]:=2821;
f[184,4]:=43966;
f[184,5]:=419736;
f[184,6]:=2748670;
f[185,2]:=92;
f[185,3]:=2852;
f[185,4]:=44671;
f[185,5]:=428821;
f[185,6]:=2822326;
f[186,2]:=93;
f[186,3]:=2883;
f[186,4]:=45407;
f[186,5]:=438040;
f[186,6]:=2897747;
f[187,2]:=93;
f[187,3]:=2914;
f[187,4]:=46128;
f[187,5]:=447419;
f[187,6]:=2974571;
f[188,2]:=94;
f[188,3]:=2945;
f[188,4]:=46880;
f[188,5]:=456936;
f[188,6]:=3053214;
f[189,2]:=94;
f[189,3]:=2977;
f[189,4]:=47616;
f[189,5]:=466616;
f[189,6]:=3133318;
f[190,2]:=95;
f[190,3]:=3008;
f[190,4]:=48384;
f[190,5]:=476437;
f[190,6]:=3215286;
f[191,2]:=95;
f[191,3]:=3040;
f[191,4]:=49136;
f[191,5]:=486424;
f[191,6]:=3298763;
f[192,2]:=96;
f[192,3]:=3072;
f[192,4]:=49920;
f[192,5]:=496555;
f[192,6]:=3384171;
f[193,2]:=96;
f[193,3]:=3104;
f[193,4]:=50688;
f[193,5]:=506856;
f[193,6]:=3471126;
f[194,2]:=97;
f[194,3]:=3136;
f[194,4]:=51488;
f[194,5]:=517304;
f[194,6]:=3560070;
f[195,2]:=97;
f[195,3]:=3169;
f[195,4]:=52272;
f[195,5]:=527925;
f[195,6]:=3650622;
f[196,2]:=98;
f[196,3]:=3201;
f[196,4]:=53089;
f[196,5]:=538696;
f[196,6]:=3743211;
f[197,2]:=98;
f[197,3]:=3234;
f[197,4]:=53889;
f[197,5]:=549644;
f[197,6]:=3837459;
f[198,2]:=99;
f[198,3]:=3267;
f[198,4]:=54722;
f[198,5]:=560745;
f[198,6]:=3933815;
f[199,2]:=99;
f[199,3]:=3300;
f[199,4]:=55539;
f[199,5]:=572026;
f[199,6]:=4031871;
f[200,2]:=100;
f[200,3]:=3333;
f[200,4]:=56389;
f[200,5]:=583464;
f[200,6]:=4132096; -
02013-08-14 16:12:49@
var
n,k,member:longint;procedure f(n,k,l:longint);
var
i:longint;
begin
if k=1 then begin inc(member); exit; end;
for i:=l to n div k do begin f(n-i,k-1,i); end;
end;begin
readln(n,k);
member:=0;
f(n,k,1);
writeln(member);
end. -
02013-07-30 16:13:56@
这题略有点坑。。。。可以有两份相同的。。
详解:
由于相同组合不同排列的方案被认为是一种 所以设
n=a1+a2+...+ak
(0<a1<=a2<=...<=ak)
令 an=an-1+xn-1
则 n=a1+(a1+x1)+(a2+x2)+...(ak-1+xk-1)
=a1+(a1+x1)+(a1+x1+x2)+...+(a1+x1+x2+...+xk-1)
=ka1+(k-1)x1+(k-2)x2+....+xk-1
转为完全背包问题即可求解 注意(a1>0)
少见的一次AC了。。。
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 536 KiB, score = 20
测试数据 #1: Accepted, time = 0 ms, mem = 536 KiB, score = 20
测试数据 #2: Accepted, time = 0 ms, mem = 532 KiB, score = 20
测试数据 #3: Accepted, time = 0 ms, mem = 536 KiB, score = 20
测试数据 #4: Accepted, time = 0 ms, mem = 536 KiB, score = 20
Accepted, time = 0 ms, mem = 536 KiB, score = 100
#include <cstdio>
#include <cstring>using namespace std;
#define MAXN 201
long long int f[MAXN];
int n,k;int main(){
scanf("%d%d",&n,&k);
memset(f,0,sizeof(f));
f[0]=1;
for (int i=0;i++<k-1;){
for (int j=i;j<=n;j++){
f[j]+=f[j-i];
}
}
long long int rec=f[n];
for (int i=k;i<=n;i++){
f[i]+=f[i-k];
}
rec=f[n]-rec;
printf("%I64d\n",rec);
return 0;
} -
02012-10-18 21:18:13@
编译通过...
├ 测试数据 01:答案正确... (0ms, 580KB)
├ 测试数据 02:答案正确... (0ms, 580KB)
├ 测试数据 03:答案正确... (0ms, 580KB)
├ 测试数据 04:答案正确... (0ms, 580KB)
├ 测试数据 05:答案正确... (0ms, 580KB)---|---|---|---|---|---|---|---|-
Accepted / 100 / 0ms / 580KB
农夫山泉有点甜
对打表的大神表示敬意 -
02012-08-21 20:22:45@
为什么我裸搜一次AC??
var
n,k,ans,i:longint;procedure search(t,kk,sum:longint);
var
i:longint;
begin
if kk>k then
begin
if sum=0 then inc(ans);
exit;
end;
for i:=t to (sum div (k-kk+1)) do
search(i,kk+1,sum-i);
end;begin
readln(n,k);
ans:=0;
for i:=1 to (n div k) do
search(i,2,n-i);
writeln(ans);
end. -
02012-08-17 19:30:51@
编译通过...
├ 测试数据 01:答案正确... (150ms, 588KB)
├ 测试数据 02:答案正确... (192ms, 588KB)
├ 测试数据 03:答案正确... (142ms, 588KB)
├ 测试数据 04:答案正确... (138ms, 588KB)
├ 测试数据 05:答案正确... (142ms, 588KB)感谢各位大牛指导!!