Power OJ 2498/recursion2498: New Year's gift Time Limit:MS Memory Limit: 65536 KB
Total Submit:12 accepted:3 Page View: 61
Submit Status discuss Description
The new Year is coming, the ╇ф want to prepare some New year gifts for the small partners, he has n unique gifts (different between gifts) and K identical gift box, he wants to send all the gifts and ensure that each box has at least one gift, because no one wants to receive empty gift box, Now, ╇ф wants to know how many options are there to place a gift?
Input multiple sets of inputs, one for each group, N and K, respectively (0<=N<=25,0<=K<=25). This group does not need to be output when n=0 and K=0 are entered at the end. Output one row per set of scenarios for MOD 1000000007.
4 2 5 3 3 1 0 0
7 25 1 Test instructions very good understanding: dp[i][j] means I put a gift into J box. 1, guarantee I>=j;2, dp[i][j]= (dp[i-1][j-1]+ (j*dp[i-1][j])%mod)%mod;//must ensure that each box is installed.
#include <bits/stdc++.h>typedefLong LongLL;ConstLL mod=1000000007; LL dp[ -][ -];intn,k;voidfuck () {dp[0][0]=1; for(LL i=1; i<= -; i++) for(LL j=1; j<=i;j++) Dp[i][j]= (dp[i-1][j-1]+ (j*dp[i-1][J])%mod)%MoD;}intmain () {fuck (); while(~SCANF ("%d%d",&n,&k)) {if(n==0&&k==0) Break; printf ("%lld\n", Dp[n][k]); } return 0;}
Power oj2498/dp/Recursion