-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsubset.cpp
34785 lines (32046 loc) · 702 KB
/
subset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <ctime>
# include <iomanip>
# include <iostream>
using namespace std;
# include "subset.hpp"
//****************************************************************************80
int asm_enum ( int n )
//****************************************************************************80
//
// Purpose:
//
// ASM_ENUM returns the number of alternating sign matrices of a given order.
//
// Discussion:
//
// N ASM_NUM
//
// 0 1
// 1 1
// 2 2
// 3 7
// 4 42
// 5 429
// 6 7436
// 7 218348
//
// A direct formula is
//
// ASM_NUM ( N ) = product ( 0 <= I <= N-1 ) ( 3 * I + 1 )! / ( N + I )!
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the order of the matrices.
//
// Output, int ASM_ENUM, the number of alternating sign matrices of
// order N.
//
{
int *a;
int asm_num;
int *b;
int *c;
int i;
int nn;
if ( n + 1 <= 0 )
{
return 0;
}
//
// Row 1
//
if ( n + 1 == 1 )
{
return 1;
}
//
// Row 2
//
if ( n + 1 == 2 )
{
return 1;
}
a = new int[n+1];
b = new int[n+1];
c = new int[n+1];
b[0] = 2;
c[0] = 2;
a[0] = 1;
a[1] = 1;
//
// Row 3 and on.
//
for ( nn = 3; nn <= n; nn++ )
{
b[nn-2] = nn;
for ( i = nn-2; 2 <= i; i-- )
{
b[i-1] = b[i-1] + b[i-2];
}
b[0] = 2;
c[nn-2] = 2;
for ( i = nn-2; 2 <= i; i--)
{
c[i-1] = c[i-1] + c[i-2];
}
c[0] = nn;
for ( i = 2; i <= nn-1; i++ )
{
a[0] = a[0] + a[i-1];
}
for ( i = 2; i <= nn; i++ )
{
a[i-1] = a[i-2] * c[i-2] / b[i-2];
}
}
asm_num = 0;
for ( i = 0; i < n; i++ )
{
asm_num = asm_num + a[i];
}
delete [] a;
delete [] b;
delete [] c;
return asm_num;
}
//****************************************************************************80
void asm_triangle ( int n, int a[] )
//****************************************************************************80
//
// Purpose:
//
// ASM_TRIANGLE returns a row of the alternating sign matrix triangle.
//
// Discussion:
//
// The first seven rows of the triangle are as follows:
//
// 1 2 3 4 5 6 7
//
// 0 1
// 1 1 1
// 2 2 3 2
// 3 7 14 14 7
// 4 42 105 135 105 42
// 5 429 1287 2002 2002 1287 429
// 6 7436 26026 47320 56784 47320 26026 7436
//
// For a given N, the value of A(J) represents entry A(I,J) of
// the triangular matrix, and gives the number of alternating sign matrices
// of order N in which the (unique) 1 in row 1 occurs in column J.
//
// Thus, of alternating sign matrices of order 3, there are
// 2 with a leading 1 in column 1:
//
// 1 0 0 1 0 0
// 0 1 0 0 0 1
// 0 0 1 0 1 0
//
// 3 with a leading 1 in column 2, and
//
// 0 1 0 0 1 0 0 1 0
// 1 0 0 0 0 1 1-1 1
// 0 0 1 1 0 0 0 1 0
//
// 2 with a leading 1 in column 3:
//
// 0 0 1 0 0 1
// 1 0 0 0 1 0
// 0 1 0 1 0 0
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the desired row.
//
// Output, int A[N+1], the entries of the row.
//
{
int *b;
int *c;
int i;
int nn;
//
if ( n + 1 <= 0 )
{
return;
}
//
// Row 1
//
a[0] = 1;
if ( n + 1 == 1 )
{
return;
}
//
// Row 2
//
a[0] = 1;
a[1] = 1;
if ( n + 1 == 2 )
{
return;
}
//
// Row 3 and on.
//
b = new int[n+1];
c = new int[n+1];
b[0] = 2;
c[0] = 2;
for ( nn = 3; nn <= n+1; nn++ )
{
b[nn-2] = nn;
for ( i = nn-2; 2 <= i; i-- )
{
b[i-1] = b[i-1] + b[i-2];
}
b[0] = 2;
c[nn-2] = 2;
for ( i = nn-2; 2 <= i; i-- )
{
c[i-1] = c[i-1] + c[i-2];
}
c[0] = nn;
for ( i = 2; i <= nn-1; i++ )
{
a[0] = a[0] + a[i-1];
}
for ( i = 2; i <= nn; i++ )
{
a[i-1] = a[i-2] * c[i-2] / b[i-2];
}
}
delete [] b;
delete [] c;
return;
}
//****************************************************************************80
void bell ( int n, int b[] )
//****************************************************************************80
//
// Purpose:
//
// BELL returns the Bell numbers from 0 to N.
//
// Discussion:
//
// The Bell number B(N) is the number of restricted growth functions
// on N.
//
// Note that the Stirling numbers of the second kind, S^m_n, count the
// number of partitions of N objects into M classes, and so it is
// true that
//
// B(N) = S^1_N + S^2_N + ... + S^N_N.
//
// The Bell number B(N) is defined as the number of partitions (of
// any size) of a set of N distinguishable objects.
//
// A partition of a set is a division of the objects of the set into
// subsets.
//
// For instance, there are 15 partitions of a set of 4 objects:
//
// (1234), (123)(4), (124)(3), (12)(34), (12)(3)(4),
// (134)(2), (13)(24), (13)(2)(4), (14)(23), (1)(234),
// (1)(23)(4), (14)(2)(3), (1)(24)(3), (1)(2)(34), (1)(2)(3)(4)
//
// and so B(4) = 15.
//
// The recursion formula is:
//
// B(I) = sum ( 1 <= J <= I ) Binomial ( I-1, J-1 ) * B(I-J)
//
// Example:
//
// N B(N)
// 0 1
// 1 1
// 2 2
// 3 5
// 4 15
// 5 52
// 6 203
// 7 877
// 8 4140
// 9 21147
// 10 115975
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 02 June 2007
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of Bell numbers desired.
//
// Output, int B[N+1], the Bell numbers from 0 to N.
//
{
int i;
int j;
b[0] = 1;
for ( i = 1; i <= n; i++ )
{
b[i] = 0;
for ( j = 1; j <= i; j++ )
{
b[i] = b[i] + b[i-j] * i4_choose ( i-1, j-1 );
}
}
return;
}
//****************************************************************************80
void bell_values ( int &n_data, int &n, int &c )
//****************************************************************************80
//
// Purpose:
//
// BELL_VALUES returns some values of the Bell numbers for testing.
//
// Modified:
//
// 08 May 2003
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Milton Abramowitz, Irene Stegun,
// Handbook of Mathematical Functions,
// US Department of Commerce, 1964,
// ISBN: 0-486-61272-4,
// LC: QA47.A34.
//
// Parameters:
//
// Input/output, int &N_DATA.
// On input, if N_DATA is 0, the first test data is returned, and N_DATA
// is set to 1. On each subsequent call, the input value of N_DATA is
// incremented and that test data item is returned, if available. When
// there is no more test data, N_DATA is set to 0.
//
// Output, int &N, the order of the Bell number.
//
// Output, int &C, the value of the Bell number.
//
{
# define N_MAX 11
int c_vec[N_MAX] = { 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975 };
int n_vec[N_MAX] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
if ( n_data < 0 )
{
n_data = 0;
}
if ( N_MAX <= n_data )
{
n_data = 0;
n = 0;
c = 0;
}
else
{
n = n_vec[n_data];
c = c_vec[n_data];
n_data = n_data + 1;
}
return;
# undef N_MAX
}
//****************************************************************************80
void catalan ( int n, int c[] )
//****************************************************************************80
//
// Purpose:
//
// CATALAN computes the Catalan numbers, from C(0) to C(N).
//
// Discussion:
//
// The Catalan number C(N) counts:
//
// 1) the number of binary trees on N vertices;
// 2) the number of ordered trees on N+1 vertices;
// 3) the number of full binary trees on 2N+1 vertices;
// 4) the number of well formed sequences of 2N parentheses;
// 5) the number of ways 2N ballots can be counted, in order,
// with N positive and N negative, so that the running sum
// is never negative;
// 6) the number of standard tableaus in a 2 by N rectangular Ferrers diagram;
// 7) the number of monotone functions from [1..N} to [1..N} which
// satisfy f(i) <= i for all i;
// 8) the number of ways to triangulate a polygon with N+2 vertices.
//
// The formula is:
//
// C(N) = (2*N)! / ( (N+1) * (N!) * (N!) )
// = 1 / (N+1) * COMB ( 2N, N )
// = 1 / (2N+1) * COMB ( 2N+1, N+1).
//
// First values:
//
// C(0) 1
// C(1) 1
// C(2) 2
// C(3) 5
// C(4) 14
// C(5) 42
// C(6) 132
// C(7) 429
// C(8) 1430
// C(9) 4862
// C(10) 16796
//
// Recursion:
//
// C(N) = 2 * (2*N-1) * C(N-1) / (N+1)
// C(N) = sum ( 1 <= I <= N-1 ) C(I) * C(N-I)
//
// Example:
//
// N = 3
//
// ()()()
// ()(())
// (()())
// (())()
// ((()))
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 08 May 2003
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Dennis Stanton, Dennis White,
// Constructive Combinatorics,
// Springer, 1986,
// ISBN: 0387963472,
// LC: QA164.S79.
//
// Parameters:
//
// Input, int N, the number of Catalan numbers desired.
//
// Output, int C[N+1], the Catalan numbers from C(0) to C(N).
//
{
int i;
if ( n < 0 )
{
return;
}
c[0] = 1;
//
// The extra parentheses ensure that the integer division is
// done AFTER the integer multiplication.
//
for ( i = 1; i <= n; i++ )
{
c[i] = ( c[i-1] * 2 * ( 2 * i - 1 ) ) / ( i + 1 );
}
return;
}
//****************************************************************************80
void catalan_row_next ( bool next, int n, int irow[] )
//****************************************************************************80
//
// Purpose:
//
// CATALAN_ROW computes row N of Catalan's triangle.
//
// Example:
//
// I\J 0 1 2 3 4 5 6
//
// 0 1
// 1 1 1
// 2 1 2 2
// 3 1 3 5 5
// 4 1 4 9 14 14
// 5 1 5 14 28 42 42
// 6 1 6 20 48 90 132 132
//
// Recursion:
//
// C(0,0) = 1
// C(I,0) = 1
// C(I,J) = 0 for I < J
// C(I,J) = C(I,J-1) + C(I-1,J)
// C(I,I) is the I-th Catalan number.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 08 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, bool NEXT, indicates whether this is a call for
// the 'next' row of the triangle.
// NEXT = FALSE, this is a startup call. Row N is desired, but
// presumably this is a first call, or row N-1 was not computed
// on the previous call.
// NEXT = TRUE, this is not the first call, and row N-1 was computed
// on the previous call. In this case, much work can be saved
// by using the information from the previous values of IROW
// to build the next values.
//
// Input, int N, the index of the row of the triangle desired.
//
// Input/output, int IROW[N+1], the row of coefficients.
// If NEXT = FALSE, then IROW is not required to be set on input.
// If NEXT = TRUE, then IROW must be set on input to the value of
// row N-1.
//
{
int i;
int j;
//
if ( n < 0 )
{
return;
}
if ( !next )
{
irow[0] = 1;
for ( i = 1; i <= n; i++ )
{
irow[i] = 0;
}
for ( i = 1; i <= n; i++ )
{
irow[0] = 1;
for ( j = 1; j <= i-1; j++ )
{
irow[j] = irow[j] + irow[j-1];
}
irow[i] = irow[i-1];
}
}
else
{
irow[0] = 1;
for ( j = 1; j <= n-1; j++ )
{
irow[j] = irow[j] + irow[j-1];
}
if ( 1 <= n )
{
irow[n] = irow[n-1];
}
}
return;
}
//****************************************************************************80
void catalan_values ( int &n_data, int &n, int &c )
//****************************************************************************80
//
// Purpose:
//
// CATALAN_VALUES returns some values of the Catalan numbers for testing.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 November 2012
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Milton Abramowitz, Irene Stegun,
// Handbook of Mathematical Functions,
// US Department of Commerce, 1964,
// ISBN: 0-486-61272-4,
// LC: QA47.A34.
//
// Parameters:
//
// Input/output, int &N_DATA.
// On input, if N_DATA is 0, the first test data is returned, and N_DATA
// is set to 1. On each subsequent call, the input value of N_DATA is
// incremented and that test data item is returned, if available. When
// there is no more test data, N_DATA is set to 0.
//
// Output, int &N, the order of the Catalan number.
//
// Output, int &C, the value of the Catalan number.
//
{
# define N_MAX 11
int c_vec[N_MAX] = { 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796 };
int n_vec[N_MAX] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
if ( n_data < 0 )
{
n_data = 0;
}
if ( N_MAX <= n_data )
{
n_data = 0;
n = 0;
c = 0;
}
else
{
n = n_vec[n_data];
c = c_vec[n_data];
n_data = n_data + 1;
}
return;
# undef N_MAX
}
//****************************************************************************80
void cfrac_to_rat ( int n, int a[], int p[], int q[] )
//****************************************************************************80
//
// Purpose:
//
// CFRAC_TO_RAT converts a monic continued fraction to an ordinary fraction.
//
// Discussion:
//
// The routine is given the monic or "simple" continued fraction with
// integer coefficients:
//
// A(1) + 1 / ( A(2) + 1 / ( A(3) ... + 1 / A(N) ) )
//
// and returns the N successive approximants P(I)/Q(I)
// to the value of the rational number represented by the continued
// fraction, with the value exactly equal to the final ratio P(N)/Q(N).
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 12 June 2004
//
// Author:
//
// Original FORTRAN77 version by John Hart, Ward Cheney, Charles Lawson,
// Hans Maehly, Charles Mesztenyi, John Rice, Henry Thatcher,
// Christoph Witzgall.
// C++ version by John Burkardt.
//
// Reference:
//
// John Hart, Ward Cheney, Charles Lawson, Hans Maehly, Charles Mesztenyi,
// John Rice, Henry Thatcher, Christoph Witzgall,
// Computer Approximations,
// Wiley, 1968.
//
// Parameters:
//
// Input, int N, the number of continued fraction coefficients.
//
// Input, int A[N], the continued fraction coefficients.
//
// Output, int P[N], Q[N], the N successive approximations
// to the value of the continued fraction.
//
{
int i;
for ( i = 0; i < n; i++ )
{
if ( i == 0 )
{
p[i] = a[i] * 1 + 0;
q[i] = a[i] * 0 + 1;
}
else if ( i == 1 )
{
p[i] = a[i] * p[i-1] + 1;
q[i] = a[i] * q[i-1] + 0;
}
else
{
p[i] = a[i] * p[i-1] + p[i-2];
q[i] = a[i] * q[i-1] + q[i-2];
}
}
return;
}
//****************************************************************************80
void cfrac_to_rfrac ( int m, double g[], double h[], double p[], double q[] )
//****************************************************************************80
//
// Purpose:
//
// CFRAC_TO_RFRAC converts a polynomial fraction from continued to rational form.
//
// Discussion:
//
// The routine accepts a continued polynomial fraction:
//
// G(1) / ( H(1) +
// G(2) * X / ( H(2) +
// G(3) * X / ( H(3) + ...
// G(M) * X / ( H(M) )...) ) )
//
// and returns the equivalent rational polynomial fraction:
//
// P(1) + P(2) * X + ... + P(L1) * X^(L1)
// -------------------------------------------------------
// Q(1) + Q(2) * X + ... + Q(L2) * X^(L2-1)
//
// where
//
// L1 = (M+1)/2
// L2 = (M+2)/2.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 12 June 2004
//
// Author:
//
// Original FORTRAN77 version by John Hart, Ward Cheney, Charles Lawson,
// Hans Maehly, Charles Mesztenyi, John Rice, Henry Thatcher,
// Christoph Witzgall.
// C++ version by John Burkardt.
//
// Reference:
//
// John Hart, Ward Cheney, Charles Lawson, Hans Maehly, Charles Mesztenyi,
// John Rice, Henry Thatcher, Christoph Witzgall,
// Computer Approximations,
// Wiley, 1968.
//
// Parameters:
//
// Input, int M, the number of continued fraction polynomial coefficients.
//
// Input, double G[M], H[M], the continued polynomial fraction coefficients.
//
// Output, double P[(M+1)/2], Q[(M+2)/2], the rational polynomial fraction
// coefficients.
//
{
double *a;
int i;
int j;
if ( m == 1 )
{
p[0] = g[0];
q[0] = h[0];
return;
}
a = new double[m*((m+2)/2)];
for ( i = 0; i < m; i++ )
{
for ( j = 0; j < (m+2)/2; j++ )
{
a[i+j*m] = 0.0;
}
}
//
// Solve for P's
//
a[0+0*m] = g[0];
a[1+0*m] = g[0] * h[1];
for ( i = 2; i < m; i++ )
{
a[i+0*m] = h[i] * a[i-1+0*m];
for ( j = 1; j < (i+2)/2; j++ )
{
a[i+j*m] = h[i] * a[i-1+j*m] + g[i] * a[i-2+(j-1)*m];
}
}
for ( j = 0; j < (m+1)/2; j++ )
{
p[j] = a[m-1+j*m];
}
//
// Solve for Q's.
//
a[0+0*m] = h[0];
a[1+0*m] = h[0] * h[1];
a[1+1*m] = g[1];
for ( i = 2; i < m; i++ )
{
a[i+0*m] = h[i] * a[i-1+0*m];
for ( j = 1; j < (i+3)/2; j++ )
{
a[i+j*m] = h[i] * a[i-1+j*m] + g[i] * a[i-2+(j-1)*m];
}
}
for ( j = 0; j < (m+2)/2; j++ )
{
q[j] = a[m-1+j*m];
}
delete [] a;
return;
}
//****************************************************************************80
char ch_cap ( char c )
//****************************************************************************80
//
// Purpose:
//
// CH_CAP capitalizes a single character.
//
// Discussion:
//
// This routine should be equivalent to the library "toupper" function.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 28 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char C, the character to capitalize.
//
// Output, char CH_CAP, the capitalized character.
//
{
if ( 97 <= c && c <= 122 )
{
c = c - 32;
}
return c;
}
//****************************************************************************80
void change_greedy ( int total, int coin_num, int coin_value[], int &change_num,
int change[] )
//****************************************************************************80
//
// Purpose:
//
// CHANGE_GREEDY makes change for a given total using the biggest coins first.
//
// Discussion:
//
// The algorithm is simply to use as many of the largest coin first,
// then the next largest, and so on.
//
// It is assumed that there is always a coin of value 1. The
// algorithm will otherwise fail!
//
// Example:
//
// Total = 17
// COIN_NUM = 3
// COIN_VALUE = (/ 1, 5, 10 /)
//
//
// # CHANGE COIN_VALUE(CHANGE)
//
// 4 3 2 1 1 10 5 1 1
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 November 2012
//
// Author:
//
// John Burkardt
//
// Parameters: