title: http://tyvj.cn/p/3119
P3119Nuclear power plant problem time: 1000ms/Space: 65536kib/java class Name: Main description
A nuclear power plant has n a pit of nuclear material, and the pits are arranged in a straight line. If the nuclear material is placed in a continuous M-pit, an explosion will occur and the nuclear substance may not be released in certain pits.
Mission: For a given N and m, the total number of solutions for placing nuclear matter without explosion
Input format
Input file only one line, two positive integers n,m (1
Output format
The output file has only a positive integer s, which indicates the total number of scenarios.
Test Sample 1 input
4 3
Output
-
Solution: Dynamic Programming F[i][j] for the first, I put the number of J explosives. Mathematical Methods not Qaq
1#include <bits/stdc++.h>2 using namespacestd;3 #defineLL Long Long4LL f[ -][6];5 intMain ()6 {7Freopen ("nucle.in","R", stdin);8Freopen ("Nucle.out","W", stdout);9 LL ans,n,m,i,j,k;Tenscanf"%lld%lld",&n,&m); OneMemset (F,0,sizeof(f));//F[i][j] For the first I, put the number of J explosives. Af[1][0]=f[1][1]=1; - for(i=2; i<=n;i++) - { the for(j=0; j<m;j++) f[i][0]+=f[i-1][j]; - for(j=0; j<m;j++) f[i][j]+=f[i-1][j-1]; - } -ans=0; + for(i=0; i<m;i++) ans+=F[n][i]; -printf"%lld", ans); + /*the mathematical method of the error A For (i=1;i<=n;i++) ans*=2; at k=n-m+1; - if (k<=0) printf ("%lld", ans); - Else - { - For (i=k;i>=1;i--) ans-=i; - printf ("%lld", ans); in }*/ - return 0; to}
Dynamic planning of TYVJ P3119 nuclear power plant