过于追求编程数量,却忽略了最重要的方法过程的思考,结果必将是不会思考,还可能养成不爱思考的习惯。
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
#include
<
stdio.h
>
2 #include < stdlib.h >
3 #include < string .h >
4
5 int n,f[ 5001 ] = { 0 },max = 0 ;
6 int a[ 5001 ],fr[ 5001 ][ 5001 ],len[ 5001 ] = { 0 };
7 int num[ 5001 ][ 60 ],sum[ 60 ] = { 0 },le[ 5001 ] = { 0 };
8
9 int plus( int * p, int * q, int l1, int l2)
10 {
11 int c,s = 0 ,i,l;
12 if (l1 > l2)l = l1;
13 else l = l2;
14 for (i = 1 ;i <= l;i ++ )
15 {
16 s += p[i] + q[i];
17 c = s % 10 ;s = s / 10 ;p[i] = c;
18 }
19 while (s != 0 )
20 {
21 c = s % 10 ;
22 s = s / 10 ;
23 p[i ++ ] = c;
24 }
25 return i - 1 ;
26 }
27
28 int main(){
29 FILE * in , * out ;
30 int i,j,k,flag,ls = 0 ;
31 memset(num, 0 , sizeof (num));
32 in = fopen( " input8.txt " , " r " );
33 out = fopen( " output.txt " , " w " );
34 fscanf( in , " %d " , & n);
35 for (i = 1 ;i <= n;i ++ )
36 {
37 fscanf( in , " %d " , & a[i]);
38 f[i] = 1 ;
39 }
40
41 for (i = 1 ;i <= n;i ++ )
42 {
43 for (j = 1 ;j < i;j ++ ) ——最长不升子序列
44 if (a[i] < a[j] && f[i] < f[j] + 1 ) f[i] = f[j] + 1 ;
45 if (max < f[i]) max = f[i];
46
47 flag = 0 ; ——对方案数的计算
48 for (j = i - 1 ;j >= 1 ;j -- )
49 if (a[i] < a[j] && f[j] + 1 == f[i])
50 {
51 for (k = 1 ;k <= len[i];k ++ )——对重复性的判断与筛选
52 if (a[j] == a[fr[i][k]]) break ;
53 if (k == len[i] + 1 )
54 {
55 flag = 1 ;
56 fr[i][k] = j;len[i] ++ ;
57 le[i] = plus(num[i],num[j],le[i],le[j]);
58 }
59 }
60 if (flag == 0 )
61 {
62 num[i][ 1 ] = 1 ;
63 le[i] = 1 ;
64 }
65 }
66
67 for (i = n;i >= 1 ;i -- )
68 if (max == f[i])
69 {
70 for (j = i + 1 ;j <= n;j ++ )
71 if (a[i] == a[j] && max == f[j]) break ;
72 if (j == n + 1 )
73 ls = plus(sum,num[i],ls,le[i]);
74 }
75
76 fprintf( out , " %d " ,max);
77 for (i = ls;i >= 1 ;i -- )
78 fprintf( out , " %d " ,sum[i]);
79 fprintf( out , " \n " );
80 fclose( in );fclose( out );
81 return 0 ;
82 }
83
84
85
2 #include < stdlib.h >
3 #include < string .h >
4
5 int n,f[ 5001 ] = { 0 },max = 0 ;
6 int a[ 5001 ],fr[ 5001 ][ 5001 ],len[ 5001 ] = { 0 };
7 int num[ 5001 ][ 60 ],sum[ 60 ] = { 0 },le[ 5001 ] = { 0 };
8
9 int plus( int * p, int * q, int l1, int l2)
10 {
11 int c,s = 0 ,i,l;
12 if (l1 > l2)l = l1;
13 else l = l2;
14 for (i = 1 ;i <= l;i ++ )
15 {
16 s += p[i] + q[i];
17 c = s % 10 ;s = s / 10 ;p[i] = c;
18 }
19 while (s != 0 )
20 {
21 c = s % 10 ;
22 s = s / 10 ;
23 p[i ++ ] = c;
24 }
25 return i - 1 ;
26 }
27
28 int main(){
29 FILE * in , * out ;
30 int i,j,k,flag,ls = 0 ;
31 memset(num, 0 , sizeof (num));
32 in = fopen( " input8.txt " , " r " );
33 out = fopen( " output.txt " , " w " );
34 fscanf( in , " %d " , & n);
35 for (i = 1 ;i <= n;i ++ )
36 {
37 fscanf( in , " %d " , & a[i]);
38 f[i] = 1 ;
39 }
40
41 for (i = 1 ;i <= n;i ++ )
42 {
43 for (j = 1 ;j < i;j ++ ) ——最长不升子序列
44 if (a[i] < a[j] && f[i] < f[j] + 1 ) f[i] = f[j] + 1 ;
45 if (max < f[i]) max = f[i];
46
47 flag = 0 ; ——对方案数的计算
48 for (j = i - 1 ;j >= 1 ;j -- )
49 if (a[i] < a[j] && f[j] + 1 == f[i])
50 {
51 for (k = 1 ;k <= len[i];k ++ )——对重复性的判断与筛选
52 if (a[j] == a[fr[i][k]]) break ;
53 if (k == len[i] + 1 )
54 {
55 flag = 1 ;
56 fr[i][k] = j;len[i] ++ ;
57 le[i] = plus(num[i],num[j],le[i],le[j]);
58 }
59 }
60 if (flag == 0 )
61 {
62 num[i][ 1 ] = 1 ;
63 le[i] = 1 ;
64 }
65 }
66
67 for (i = n;i >= 1 ;i -- )
68 if (max == f[i])
69 {
70 for (j = i + 1 ;j <= n;j ++ )
71 if (a[i] == a[j] && max == f[j]) break ;
72 if (j == n + 1 )
73 ls = plus(sum,num[i],ls,le[i]);
74 }
75
76 fprintf( out , " %d " ,max);
77 for (i = ls;i >= 1 ;i -- )
78 fprintf( out , " %d " ,sum[i]);
79 fprintf( out , " \n " );
80 fclose( in );fclose( out );
81 return 0 ;
82 }
83
84
85
拿到程序要自己思考,别拿别人的在那里死啃,越看越看不懂,然后就浮躁了,就迷茫了,就失去信心了。自己耐心
分析比什么都强,即使几个小时就自己分析了还没结果,也比花10分钟学了别人的强!
我们缺的就是创造力啊。有时间看看这些视频,看看创造力是如何造就不平凡的。
http://www.tudou.com/v/9H4IrWGsfl8/