9 条题解

  • 2
    @ 2024-7-20 11:55:39

    #include <bits/stdc++.h> using namespace std; int a[1000][1000]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ a[i][1]=2;a[i][i]=2; for(int j=2;j<n;j++){ a[i][j]=a[i-1][j]+a[i-1][j-1]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(a[i][j]==0){ continue; } cout<<a[i][j]<<" "; } cout<<endl; } return 0; }

    • 2
      @ 2024-7-20 11:52:09
      //P5732  【深基5.习7】杨辉三角
      #include<bits/stdc++.h>
      using namespace std;
      int a[100][100];
      int main(){
      	int n;
      	cin>>n;
      	for(int i = 1;i<=n;i++){
      		for(int j  =1;j<=i;j++){
      			if(j == 1 or i==j) 
      			//对角线和第一列赋值 
      				a[i][j] = 1;
      			else 
      			//其他正常的元素进行赋值 
      				a[i][j] = a[i-1][j-1]+a[i-1][j];
      			
      		}
      	}
      	for(int i =1;i<=n;i++){
      		for(int j = 1;j<=i;j++){
      			cout<<a[i][j]<<" ";
      		}
      		cout<<endl;
      	}
      	return 0;
      }
      
      ```
      第11行和14行是对所有1的赋值
      第15行是用公式赋值
      • 0
        @ 2024-9-11 20:48:04
        using namespace std;
        int a[8848][8848];
        int main(){
        	int n,i,j;
        	cin>>n;
        for(i=1;i<=n;i++){
        	for(j=1;j<=i;j++){
        		if(j==1 or i==j)
        		a[i][j]=1;
        		else
        		a[i][j]=a[i-1][j-1]+a[i-1][j];
        	}
        }
        for(i=1;i<=n;i++){
        	for(j=1;j<=i;j++){
        		cout<<a[i][j]<<" ";
        	}
        	cout<<endl;
        }
        	return 0;
        }
        • -2
          @ 2024-7-18 11:16:38
          #include<bits/stdc++.h>
          using namespace std;
          int a[21][21];
          int main(){
          	int n;
          	cin>>n;
          	a[1][1]=1;
          	for(int i=1;i<=n+1;i++){
          		for(int k=2;k<=n;k++){
          		a[i][k]=a[i-1][k-1]+a[i-1][k];
          	}
          	}
          	for(int i=2;i<=n+1;i++){
          		for(int k=2;k<=n+1;k++){
          			if(a[i][k]==0){
          				continue;
          			}
          		cout<<a[i][k]<<" ";
          		if(i==n+1 and k==n){
          		cout<<"1";	
          		}
          	}
          	cout<<endl;
          	}
          	return 0;
          • -3
            @ 2024-7-20 11:51:39
            #include<bits/stdc++.h>
            using namespace std;
            const int maxn=50;
            int a[maxn][maxn];
            int main(){
            	int n;
            	cin>>n;
            	for(int i=1;i<=n;i++){
            		a[i][1]=1;a[i][i]=1;
            		for(int j=2;j<i;j++){
            			a[i][j]=a[i-1][j-1]+a[i-1][j];
            		}
            	}
            	for(int i=1;i<=n;i++){
            		for(int j=1;j<=i;j++){
            			cout<<a[i][j]<<" ";
            		}
            		cout<<endl;
            	}
            		return 0;
            }
            
            • -3
              @ 2024-7-20 11:48:18

              #include<bits/stdc++.h> using namespace std; int a[21][21]; int main(){ int n; cin>>n; a[1][1]=1; for(int i=1;i<=n+1;i++){ for(int k=2;k<=n;k++){ a[i][k]=a[i-1][k-1]+a[i-1][k]; } } for(int i=2;i<=n+1;i++){ for(int k=2;k<=n+1;k++){ if(a[i][k]0){ continue; } cout<<a[i][k]<<" "; if(in+1 and k==n){ cout<<"1"; } } cout<<endl; } return 0;

              • -3
                @ 2024-7-19 12:00:24

                #include <bits/stdc++.h> using namespace std; int q[100][100]; int main(){ int a,z,s,x,d,c,f=0,v=0,g=0; cin>>a; for(z=1;z<=a;z++){ q[z][1]=1; } for(z=1;z<=a;z++){ for(s=z;s==z;s++){ q[z][s]=1; } } for(z=3;z<=a;z++){ for(s=2;s<a;s++){ q[z][s]=q[z-1][s]+q[z-1][s-1]; } } for(z=1;z<=a;z++){ for(s=1;s<=z;s++){ cout<<q[z][s]<<" "; } cout<<endl; } return 0; }

                • -4
                  @ 2024-7-20 11:55:56
                  #include<bits/stdc++.h>
                  using namespace std;
                  int a[21][21];
                  int main(){
                  	int n,i,j;
                  	cin>>n;
                  	a[1][1]=1;
                  	for( i=1;i<=n+1;i++){
                  		for( j=2;j<=n;j++){
                  		a[i][j]=a[i-1][j-1]+a[i-1][j];
                  	}
                  	}
                  	for( i=2;i<=n+1;i++){
                  		for( j=2;j<=n+1;j++){
                  			if(a[i][j]==0){
                  				continue;
                  			}
                  		cout<<a[i][j]<<" ";
                  		if(i==n+1 and j==n){
                  		cout<<"1";	
                  		}
                  	}
                  	cout<<endl;
                  	}
                  	return 0;
                  }
                  • -4
                    @ 2024-7-20 11:52:18
                    #include<bits/stdc++.h>
                    using namespace std;
                    const int a=21;
                    int b[a][a],s;
                    int main(){
                    	cin>>s;
                    	for(int i=1;i<=s;i++){
                    		b[i][1]=b[i][i]=1;
                    		for(int j=2;j<i;j++){
                    			b[i][j]=b[i-1][j-1]+b[i-1][j];
                    		}
                    	}
                    	for(int i=1;i<=s;i++){
                    		for(int j=1;j<=i;j++){
                    			cout<<b[i][j]<<" ";
                    		}
                    		cout<<endl;
                    	}
                    	return 0; 
                    }
                    
                    • 1

                    信息

                    ID
                    2007
                    时间
                    1000ms
                    内存
                    125MiB
                    难度
                    4
                    标签
                    (无)
                    递交数
                    185
                    已通过
                    81
                    上传者