Find the Number of Integer Solutions to X1+x2+x3+x421
Solution Equation X1 + X2 + X3 = 15 Number of Integer Solutions
Requirements 0 ≤ x1 ≤ 5, 0 ≤ x 2 ≤ 6, 0 ≤ x3 ≤ 7.
Solution: Let N are all non-negative individual solutions (X1, X2, X3),
A1 is the solution of X1 ≥ 6; Y1 = X1-6 ≥ 0 solutions;
A2 is the solution of X2 ≥ 7; Y2 = X2-7 ≥ 0 solutions;
A3 is the solution of X3 ≥ 8. Y3 = X3-8 ≥ 0 solution
The number of A1 is equivalent to the number of non-negative syndrome,
It is C (3 + 9-1, 9) = C (11, 2)
A number of A2, equivalent to X1 + (Y2 + 7) + X3 = 15 to seek non-negative
Number of numbers. C (3 + 8-1, 8) = C (10, 2)
The number of A3, equivalent to X1 + X2 + (Y3 + 8) = 15 to seek non-negative
Number of numbers. C (3 + 7-1, 7) = c (9, 2)
Number of nature A1∩a2 is equivalent to
(Y1 + 6) + (Y2 + 7) + x3 = 15 for the number of non-negative syndrome.
The number of non-negative integer solutions of Y1 + Y2 + X3 = 2, the number of people is
C(3+2-1,2)=C(4,2)
The number of solutions of nature A1∩A3 is equivalent to
(Y1 + 6) + X2 + (Y3 + 8) = 15 The number of non-negative syntax solutions.
The number of non-negative integer solutions of Y1 + X2 + Y3 = 1, the number of people is
C(3+1-1,1)=C(3,1)
Number of nature A2∩a3 is equivalent to
X1 + (Y2 + 7) + (Y3 + 8) = 15 The number of non-negative syntax solutions.
The number of non-negative integer solutions of X1 + Y2 + Y3 = 0 is as fixed.
C(3+0-1,0)=C(2,0)
Number of nature A1∩a2∩a3, equivalent to
(Y1 + 6) + (Y2 + 7) + (Y3 + 8) = 15 The number of non-negative syntax solutions.
The number of non-negative integer solutions of Y1 + Y2 + Y3 = -6, the number of people is 0
B(0)=a(0)-a(1)+a(2)-a(3)
=C(17,2)-(c(11,2)+C(10,2)+C(9,2))+(c(4,2)+C(3,1)+C(2,0))-0
=10
Test questions visible: https://www.cnblogs.com/yuiffy/p/3909970.html
(CF451E DEVU AND FLOWERS (SKL MLAL LUCAS Theorem ")
If it is the number of integer solutions of X1 + X2 + X3 <= 15
It can be considered 3 + 15 positions, and then three variables are placed casually, that is, C (15 + 3, 3) is specified.
See: https: //begin.lydsy.com/judgeonline/problem.php? Id = 3957
If x1, x2, x3 has some limitations, it will be made according to the above questions.
Related Example: BZOJ3027 SWEET (Of course this question can also be solved by the method of mother function, see this LINK)
https://www.cnblogs.com/cutemush/p/11988461.html
#include<bits/stdc++.h> #define maxn 2005 #define mod 2004 #define pii pair<int,int> #define F first #define S second #define mp make_pair #define LL long long using namespace std; int n,a,b,m[20],ans; int C(int a,int b){ if(a < b) return 0; LL fac = 1 , ret = 1; for(int i=1;i<=b;i++) fac *= i; LL Mod = fac * mod; for(int i=1;i<=b;i++) ret = 1ll * ret * (a-i+1) % Mod; return ret / fac; } void dfs(int s,int ad,int xs) // s represents which item selected, the AD representative equation needs to subtract digital, XS representative factor / / According to the generalized memory theorem, send one of the unsatisfactory conditions to the overall, plus two two unsatisfactory conditions, minus three three unsatisfactory conditions. //Zero or positive integer solution x1 + x2 + x3 <= 15, that is, required: x1 ≥ 0, x2 ≥ 0, x3 ≥ 0. //C(3+15,15)=C(18,3) { if(s == n+1) { ans = (ans + 1ll * xs * (C(b-ad+n,n) - C(a-1-ad+n,n))) % mod; return; } dfs(s+1,ad,xs); DFS (S + 1, AD + M [S] + 1, -XS); // Note AD + M [S] +1 This coefficient } int main(){ scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++) scanf("%d",&m[i]); dfs(1,0,1); printf("%d\n",(ans+mod)%mod); }
Another program is actually similar, adding a solution process
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define maxn 15 const int mod=2004; int n,l,r,ans; int a[maxn]; inline int read(){ int x=0,f=1; char ch=getchar(); for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1; for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; return x*f; } int C(int n,int m){ if (n<m) return 0; long long p=mod,ret=1; for (int i=1;i<=m;i++) p*=i; for (int i=n-m+1;i<=n;i++) ret=ret*i%p; return ret/(p/mod)%mod; } void dfs(int x,int type,int sum,int pps){ if (x>n){ans=(ans+type*C(n+pps-sum,n))%mod; return;} dfs(x+1,type,sum,pps),dfs(x+1,-type,sum+a[x],pps); } int solve(int n){ans=0,dfs(1,1,0,n); return (ans+mod)%mod;} int main(){ n=read(),l=read(),r=read(); for (int i=1;i<=n;i++) a[i]=read()+1; int ans=(solve(r)-solve(l-1)+mod)%mod; printf("%d\n",ans); return 0; } /* input 2 4 7 2 3 output Solve: Not subject to any restriction x+y<=7 Solution is C (9, 2) = 36 Plus limit 1, ie X + Y <= 7, but x> = 3 Then equivalent to equation X + Y <= 4, its solution number is c (6, 2) = 15 Plus limit 2, ie X + Y <= 7, but y> = 4 Then equivalent to equation X + Y <= 3, its solution is c (5, 2) = 10 If both limitations are added Equivalent to equation x + y <= 7-3-4 = 0, its program number is 1 So equation x+y<=7 0 <= x <= 2, 0 <= y <= 3 solutions 36-15-10 + 1 = 12 solutions Use the same method to find out X + Y <= 3 solution, there are 9 kinds of So 12-9 = 3 for solving the problem */
Discuz! X2 and jQuery is incompatible solution
1. Write your JS script into an external file. 2. Open Template / Default / Common / Header_Common.htm Tip: If you use other styles and the style rewritten Header_Common.htm file, you need to change t...
Find the Number of Integer Solutions to X1+x2+x3+x421
Source: https://programmerall.com/article/42141664517/