| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2627 人关注过本帖
标题:复杂的数组计算
只看楼主 加入收藏
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
结帖率:93.33%
收藏
已结贴  问题点数:40 回复次数:12 
复杂的数组计算
假设有一个数组如下(第一行为该数组内的每一个具体的数,第二行为第一行数组内的每一个具体的数所对应的位置,比如第一行的85是第16个数,第一行的87是第4个数,之所以要把第二行数列出来,是为了后面好叙述的需要。)第一行的数可以手动输入:
10 10 10 45 87 66 10 10 10 10 10 10 10 10 10 10 85 47 15 10 10  
0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20

共计21个元素,最先一个数(位置为0的数)是10,现在来计算,只讨论与最先的这个数相同的数,其他的数不在考虑范围内,这样一来,第一行不是10的数假设都用0来表示(第二行的的数不变),就变成了:
10 10 10 0   0  0  10 10 10 10 10 10 10 10 10 10 0  0   0 10 10
0  1  2  3   4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20  
现在来做计算,用第二行的这21个数(0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20)做减法运算,减法规则:两两相减法(当然,只限定大数减小数,共要减20+19+18+17+。。。+3+2+1次)。然后看减后的结果所对应的数的第一行所对应的数是不是10,是就计数k+1,依次类推,最后要看k最大是多少。举例如下:
第二行的0 1 2  这3个数两两相减就是1-0=1 2-0 2-1 。它们的差分别是1 2 1 ,它们的差值所对应的第一行的数都是10,满足条件,所以这里k=3.但是 k=3是不是最大值呢?不是的,最大值是k=6.//备注,每组数里一定要包含0这位数位(不然无效)。
它们分别是  0,1,2,8,9,10  k=6
            0,1,2,8,9,15  k=6
            0,1,2,8,14,15  k=6
            0,1,2,9,10,11  k=6
            0,1,2,10,11,12  k=6
            0,1,2,11,12,13  k=6
            0,1,2,12,13,14  k=6
            0,1,2,13,14,15  k=6
            0,1,7,8,9,15  k=6
            0,1,7,8,9,20  k=6
            0,1,7,8,14,15  k=6
            0,1,7,8,14,20  k=6
            0,1,7,13,14,15  k=6
            0,1,7,13,14,20  k=6
            0,1,8,9,10,20  k=6
            0,1,9,10,11,20  k=6
            0,1,10,11,12,20  k=6
            0,1,11,12,13,20  k=6
            0,1,12,13,14,20  k=6
            0,6,7,8,14,15  k=6  
            0,6,7,8,14,20  k=6
            0,6,7,8,19,20  k=6
            0,6,7,13,14,15  k=6   
            0,6,7,13,14,20  k=6
            0,6,7,13,19,20  k=6
            0,6,12,13,14,20  k=6
            0,6,12,13,19,20  k=6
            0,7,8,9,19,20  k=6
            0,8,9,10,19,20  k=6
            0,9,10,11,19,20  k=6
            0,10,11,12,19,20  k=6
            0,11,12,13,19,20  k=6

[此贴子已经被作者于2020-10-8 20:46编辑过]

搜索更多相关主题的帖子: 个数 数组 对应 计算 一行 
2020-10-02 11:18
lin5161678
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:45
帖 子:1136
专家分:3729
注 册:2011-12-3
收藏
得分:0 
只有一个要求 原题发出来
不要发这种思考一半的东西

https://zh.
2020-10-05 03:20
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
没有原题。
2020-10-05 09:50
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
目前思考到这里了。还不完善。
程序代码:
#include <stdio.h>
#include <stdlib.h>

 
int main()
{
    int a[21]={ 10 ,10, 10, 10, 87, 66 ,10, 10 ,10, 10, 10,10, 10, 10, 10, 10 ,85 ,47, 15, 10 ,10 },m1,m2,m3,k=1,p=21;
    for(m1=1;m1<p;m1++) 
       {
           if(a[0]==10)
             {   
                 if(a[m1]-a[0]==0)
                  {  printf("m1=%d ",m1);
                     k=k+1;
                        printf( "%d,%d ",0,m1);
                     printf( " k = %d ",k);
                     printf("\n");
                     for(m2=1;m2<p-m1;m2++)
                     if(a[m2]-a[0]==0)
                       {  printf("m2=%d ",m2);
                        k=k+1;
                             printf( "%d,%d,%d ",0,m1,m1+m2);
                          printf( " k = %d ",k);
                          printf("\n");
                          for(m3=1;m3<p-m1-m2;m3++)
                        if(a[3]-a[0]==0)
                             {   printf("m3=%d ",m3);
                              k=k+1;
                                   printf( "%d,%d,%d ,%d",0,m1,m1+m2,m1+m2+m3);
                                printf( " k = %d ",k);
                                printf("\n");
                                if(a[4]-a[0]==0)
                                  {  k=k+1;
                                        printf( "%d,%d,%d ,%d,%d",0,1,2,3,4);
                                     printf( " k = %d ",k);
                                     printf("\n");
                                     if(a[5]-a[0]==0)
                                      {  k=k+1;
                                            printf( "%d,%d,%d ,%d,%d,%d",0,1,2,3,4,5);
                                         printf( " k = %d ",k);
                                         printf("\n");
                                          if(a[6]-a[0]==0)
                                           {  k=k+1;
                                                 printf( "%d,%d,%d ,%d,%d,%d,%d",0,1,2,3,4,5,6);
                                              printf( " k = %d ",k);
                                              printf("\n");
                                              if(a[7]-a[0]==0)
                                                {  k=k+1;
                                                      printf( "%d,%d,%d ,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7);
                                                   printf( " k = %d ",k);
                                                   printf("\n");
                                                   if(a[8]-a[0]==0)
                                                    {  k=k+1;
                                                          printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8);
                                                       printf( " k = %d ",k);
                                                       printf("\n");
                                                       if(a[9]-a[0]==0)
                                                         {  k=k+1;
                                                               printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9);
                                                            printf( " k = %d ",k);
                                                            printf("\n");
                                                            if(a[10]-a[0]==0)
                                                              {  k=k+1;
                                                                    printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10);
                                                                 printf( " k = %d ",k);
                                                                 printf("\n");
                                                                 if(a[11]-a[0]==0)
                                                                   {  k=k+1;
                                                                         printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11);
                                                                      printf( " k = %d ",k);
                                                                      printf("\n");
                                                                   if(a[12]-a[0]==0)
                                                                        {  k=k+1;
                                                                              printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12);
                                                                           printf( " k = %d ",k);
                                                                           printf("\n");
                                                                         if(a[13]-a[0]==0)
                                                                              {  k=k+1;
                                                                                    printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13);
                                                                                 printf( " k = %d ",k);
                                                                                 printf("\n");
                                                                                 if(a[14]-a[0]==0)
                                                                                  {  k=k+1;
                                                                                        printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14);
                                                                                     printf( " k = %d ",k);
                                                                                     printf("\n");
                                                                                   if(a[15]-a[0]==0)
                                                                                       {  k=k+1;
                                                                                             printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
                                                                                          printf( " k = %d ",k);
                                                                                         printf("\n");
                                                                                       if(a[16]-a[0]==0)
                                                                                             {  k=k+1;
                                                                                                   printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
                                                                                                printf( " k = %d ",k);
                                                                                                printf("\n");
                                                                                             if(a[17]-a[0]==0)
                                                                                                   {  k=k+1;
                                                                                                         printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17);
                                                                                                      printf( " k = %d ",k);
                                                                                                      printf("\n");
                                                                                                    if(a[18]-a[0]==0)
                                                                                                         {  k=k+1;
                                                                                                               printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18);
                                                                                                            printf( " k = %d ",k);
                                                                                                            printf("\n");
                                                                                                           if(a[19]-a[0]==0)
                                                                                                                {  k=k+1;
                                                                                                                      printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
                                                                                                                   printf( " k = %d ",k);
                                                                                                                   printf("\n");
                                                                                                                if(a[20]-a[0]==0)
                                                                                                                       {  k=k+1;
                                                                                                                             printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
                                                                                                                          printf( " k = %d ",k);
                                                                                                                          printf("\n");
                                                                                                                        if(a[21]-a[0]==0)
                                                                                                                              {  k=k+1;
                                                                                                                                    printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21);
                                                                                                                                 printf( " k = %d ",k);
                                                                                                                                 printf("\n");
                                                                                                                           }   
                                                                                                                       }   
                                                                                                            }     
                                                                                                        }
                                                                                                }
                                                                                           }
                                                                                   }
                                                                               }
                                                                          }
                                                                     }
                                                                
                                                                }
                                                                 
                                                           }
                                                      }
                                                 }
                                            }
                                      }
                                  }
                                 
                             }
                            
                          }
                    k=0;
                   }
                     
                     k=0;
                  }
             k=0;
              }
           k=0;
           system ("pause");
       }
     printf("\n"); 
   return 0;
}


[此贴子已经被作者于2020-10-6 20:40编辑过]

2020-10-06 20:18
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
又进一步了:
程序代码:
#include <stdio.h>
#include <stdlib.h>

 
int main()
{
    int a[21]={ 10 ,10, 10, 45, 87, 66 ,10, 10 ,10, 10, 10,10, 10, 10, 10, 10 ,85 ,47, 15, 10 ,10 },m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15,m16,m17,m18,m19,m20,k=1,p=21;
    
    for(m1=1;m1<p;m1++) 
       {
           if(a[m1]-a[0]==0)
                  {  printf("m1=%d ",m1);
                     k=2;                     
                        printf( "%d,%d ",0,m1);
                     printf( " k = %d ",k);
                     printf("\n");
                     for(m2=1;m2<p-m1;m2++)//======
                     if(a[m1+m2]-a[m1]==0)
                       {  printf("m2=%d ",m2);
                        k=3;
                             printf( "%d,%d,%d ",0,m1,m1+m2);
                          printf( " k = %d ",k);
                          printf("\n");
                          for(m3=1;m3<p-m1-m2;m3++)//======
                        if(a[m1+m2+m3]-a[m2]==0)
                             {   printf("m3=%d ",m3);
                              k=4;
                                   printf( "%d,%d,%d ,%d",0,m1,m1+m2,m1+m2+m3);
                                printf( " k = %d ",k);
                                printf("\n");
                                for(m4=1;m4<p-m1-m2-m3;m4++)//======
                                if(a[m1+m2+m3+m4]-a[m3]==0)
                                  {  printf("m4=%d ",m4);
                                  k=5;
                                        printf( "%d,%d,%d ,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4);
                                     printf( " k = %d ",k);
                                     printf("\n");
                                     for(m5=1;m5<p-m1-m2-m3-m4;m5++)//======
                                     if(a[m1+m2+m3+m4+m5]-a[m4]==0)
                                      {   printf("m5=%d ",m5);
                                       k=6;
                                            printf( "%d,%d,%d ,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5);
                                         printf( " k = %d ",k);
                                         printf("\n");
                                         for(m6=1;m6<p-m1-m2-m3-m4-m5;m6++)//======
                                          if(a[m1+m2+m3+m4+m5+m6]-a[m5]==0)
                                           {  printf("m6=%d ",m6);
                                           k=7;
                                                 printf( "%d,%d,%d ,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6);
                                              printf( " k = %d ",k);
                                              printf("\n");
                                             for(m7=1;m7<p-m1-m2-m3-m4-m5-m6;m7++)//======
                                              if(a[m1+m2+m3+m4+m5+m6+m7]-a[m6]==0)
                                                {  printf("m7=%d ",m7);
                                                k=8;
                                                      printf( "%d,%d,%d ,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7);
                                                   printf( " k = %d ",k);
                                                   printf("\n");
                                                   for(m8=1;m8<p-m1-m2-m3-m4-m5-m6-m7;m8++)//======
                                                  if(a[m1+m2+m3+m4+m5+m6+m7+m8]-a[m7]==0)
                                                    {  printf("m8=%d ",m8);
                                                     k=9;
                                                          printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8);
                                                       printf( " k = %d ",k);
                                                       printf("\n");
                                                      for(m9=1;m9<p-m1-m2-m3-m4-m5-m6-m7-m8;m9++)//======
                                                       if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9]-a[m8]==0)
                                                         {  printf("m9=%d ",m9);
                                                         k=10;
                                                               printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9);
                                                            printf( " k = %d ",k);
                                                            printf("\n");
                                                            for(m10=1;m10<p-m1-m2-m3-m4-m5-m6-m7-m8-m9;m10++)//======
                                                            if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10]-a[m9]==0)
                                                              {  printf("m10=%d ",m10);
                                                              k=11;
                                                                    printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10);
                                                                 printf( " k = %d ",k);
                                                                 printf("\n");
                                                                 for(m11=1;m11<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10;m11++)//======
                                                                 if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11]-a[m10]==0)
                                                                   {  printf("m11=%d ",m11);
                                                                   k=12;
                                                                         printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11);
                                                                      printf( " k = %d ",k);
                                                                      printf("\n");
                                                                    for(m12=1;m12<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11;m12++)//======
                                                                   if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12]-a[m11]==0)
                                                                        {   printf("m12=%d ",m12);
                                                                         k=13;
                                                                              printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12);
                                                                           printf( " k = %d ",k);
                                                                           printf("\n");
                                                                           for(m13=1;m13<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12;m13++)//======
                                                                         if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13]-a[m12]==0)
                                                                              {  printf("m13=%d ",m13);
                                                                              k=14;
                                                                                    printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13);
                                                                                 printf( " k = %d ",k);
                                                                                 printf("\n");
                                                                                 for(m14=1;m14<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13;m14++)//======
                                                                                 if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14]-a[m13]==0)
                                                                                  {  printf("m14=%d ",m14);
                                                                                   k=15;
                                                                                        printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14);
                                                                                     printf( " k = %d ",k);
                                                                                     printf("\n");
                                                                                     for(m15=1;m15<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14;m15++)//======
                                                                                   if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15]-a[m14]==0)
                                                                                       { printf("m15=%d ",m15);
                                                                                        k=16;
                                                                                             printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15);
                                                                                          printf( " k = %d ",k);
                                                                                          printf("\n");
                                                                                          for(m16=1;m16<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15;m16++)//======
                                                                                       if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16]-a[m15]==0)
                                                                                             {  printf("m16=%d ",m16);
                                                                                             k=17;
                                                                                                   printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16);
                                                                                                printf( " k = %d ",k);
                                                                                                printf("\n");
                                                                                                for(m17=1;m17<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15-m16;m17++)//======
                                                                                             if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17]-a[m16]==0)
                                                                                                   {  printf("m17=%d ",m17);
                                                                                                   k=18;
                                                                                                         printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17);
                                                                                                      printf( " k = %d ",k);
                                                                                                      printf("\n");
                                                                                                      for(m18=1;m18<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15-m16-m17;m18++)//======
                                                                                                    if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18]-a[m17]==0)
                                                                                                         {  printf("m18=%d ",m18);
                                                                                                         k=19;
                                                                                                               printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18);
                                                                                                            printf( " k = %d ",k);
                                                                                                            printf("\n");
                                                                                                            for(m19=1;m19<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15-m16-m17-m18;m19++)//======
                                                                                                           if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18+m19]-a[m18]==0)
                                                                                                                {  printf("m19=%d ",m19);
                                                                                                                k=20;
                                                                                                                      printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18+m19);
                                                                                                                   printf( " k = %d ",k);
                                                                                                                   printf("\n");
                                                                                                                   for(m20=1;m20<p-m1-m2-m3-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15-m16-m17-m18-m19;m20++)//======
                                                                                                                if(a[m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18+m19+m20]-a[m19]==0)
                                                                                                                       {  printf("m20=%d ",m20);
                                                                                                                       k=21;
                                                                                                                             printf( "%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",0,m1,m1+m2,m1+m2+m3,m1+m2+m3+m4,m1+m2+m3+m4+m5,m1+m2+m3+m4+m5+m6,m1+m2+m3+m4+m5+m6+m7,m1+m2+m3+m4+m5+m6+m7+m8,m1+m2+m3+m4+m5+m6+m7+m8+m9,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18+m19,m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12+m13+m14+m15+m16+m17+m18+m19+m20);
                                                                                                                          printf( " k = %d ",k);
                                                                                                                          printf("\n");
                                                                                                                        
                                                                                                                       }   
                                                                                                            }     
                                                                                                        }
                                                                                                }
                                                                                           }
                                                                                   }
                                                                               }
                                                                          }
                                                                     }
                                                                
                                                                }
                                                                 
                                                           }
                                                      }
                                                 }
                                            }
                                      }
                                  }
                             }
                            
                          }
                   }
                 }
           k=0;
           system ("pause");
       }
     printf("\n"); 
   return 0;
}
2020-10-08 22:05
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:0 
说实话,我看不懂题目要求。

#include <stdio.h>

size_t foo( const int a[static 21] )
{
    size_t k_max = 0;

    for( unsigned m=0; m!=1u<<20; ++m )
    {
        _Bool bok = 1;
        size_t k = 0;
        for( unsigned i=0; bok && i!=21; ++i )
        {
            if( (~m)&(1u<<i) )
            {
                ++k;
                for( unsigned j=i+1; bok && j!=21; ++j )
                {
                    if( (~m)&(1u<<j) )
                        bok = a[j-i]==a[0];
                }
            }
        }

        if( bok && k!=0 && k>=k_max )
        {
            if( k>k_max && k_max!=0 )
                puts( "... ignore above\n" );

            k_max = k;

            for( unsigned i=0; i!=21; ++i )
                if( (~m)&(1u<<(21-1-i)) )
                    printf( "%u, ", i );
            printf( "k=%u\n", k_max );
        }
    }

    return k_max;
}

int main( void )
{
    const int a[21] = { 10, 10, 10, 45, 87, 66 ,10, 10 ,10, 10, 10,10, 10, 10, 10, 10 ,85 ,47, 15, 10, 10 };
    foo( a );
}


输出
0, 1, 2, 8, 9, 10, k=6
0, 1, 2, 8, 9, 15, k=6
0, 1, 2, 8, 14, 15, k=6
0, 1, 2, 9, 10, 11, k=6
0, 1, 2, 10, 11, 12, k=6
0, 1, 2, 11, 12, 13, k=6
0, 1, 2, 12, 13, 14, k=6
0, 1, 2, 13, 14, 15, k=6
0, 1, 7, 8, 9, 15, k=6
0, 1, 7, 8, 9, 20, k=6
0, 1, 7, 8, 14, 15, k=6
0, 1, 7, 8, 14, 20, k=6
0, 1, 7, 13, 14, 15, k=6
0, 1, 7, 13, 14, 20, k=6
0, 1, 8, 9, 10, 20, k=6
0, 1, 9, 10, 11, 20, k=6
0, 1, 10, 11, 12, 20, k=6
0, 1, 11, 12, 13, 20, k=6
0, 1, 12, 13, 14, 20, k=6
0, 6, 7, 8, 14, 15, k=6
0, 6, 7, 8, 14, 20, k=6
0, 6, 7, 8, 19, 20, k=6
0, 6, 7, 13, 14, 15, k=6
0, 6, 7, 13, 14, 20, k=6
0, 6, 7, 13, 19, 20, k=6
0, 6, 12, 13, 14, 20, k=6
0, 6, 12, 13, 19, 20, k=6
0, 7, 8, 9, 19, 20, k=6
0, 8, 9, 10, 19, 20, k=6
0, 9, 10, 11, 19, 20, k=6
0, 10, 11, 12, 19, 20, k=6
0, 11, 12, 13, 19, 20, k=6
2020-10-09 10:16
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
size_t foo( const int a[static 21] )
语法错误:    [Error] expected primary-expression before 'static'
            [Error] expected initializer before 'static'
2020-10-09 19:35
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:0 
以下是引用自学的数学在2020-10-9 19:35:28的发言:

size_t foo( const int a[static 21] )
语法错误:    [Error] expected primary-expression before 'static'
            [Error] expected initializer before 'static'

你用符合C标准的编译器试试,
如果没有符合标准的编译器的话,那就将 static 21 删除掉吧
2020-10-09 20:46
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
如果size_t foo( const int a[] ) 则:
In function 'size_t foo(const int*)':
[Error] '_Bool' was not declared in this scope
2020-10-09 20:52
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:0 
以下是引用自学的数学在2020-10-9 20:52:08的发言:

如果size_t foo( const int a[] ) 则:
In function 'size_t foo(const int*)':
[Error] '_Bool' was not declared in this scope

你用的是多古老的C编译器呀,那就将 _Bool 改为 unsigned 等吧
2020-10-10 08:37
快速回复:复杂的数组计算
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.070080 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved